sendgrid google app engine python DistributionNotF

2019-09-05 08:19发布

I am integrating Sendgrid into a Google App Engine Python project.

Sendgrid is installed through pip, and from the shell command line, functions correctly.

I have copied the sendgrid folder into my gae project folder.

Using the same example code (from sendgrid-python github page) that works in the shell, I receive the following error:

Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in call
rv = self.handle_exception(request, response, e)
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in call
rv = self.router.dispatch(request, response)
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in call
return handler.dispatch()
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(args, kwargs)
File "C:***route", line 260, in post
sg = sendgrid.SendGridClient('username', 'password')
File "C:\appname\sendgrid\sendgrid.py", line 36, in init
self.useragent = 'sendgrid/' + pkg_resources.get_distribution('sendgrid').version + ';python'
File "C:\Program Files\Google\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 311, in get_distribution
if isinstance(dist,Requirement): dist = get_provider(dist)
File "C:\Program Files\Google\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 197, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "C:\Program Files\Google\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Program Files\Google\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
DistributionNotFound: sendgrid

Thanks for your help!

EDIT: I have tried upgrading and re-installing pip and setuptools, also installing distribute and distribution. Nothing worked. I have searched through the web for similar errors, whether from distributionnotfound or from pkg_resource and nothing.

EDIT 2: Instead of installing with 'pip install sendgrid', I removed sendgrid and downloaded by zip from github sendgrid-python, then running setup.py. Initially the results were the same, sendgrid works from shell, but not from GAE. However, the zip download includes a DIST folder, which if copied into the GAE directory along with the sendgrid folder, removes the DistributionNotFound error. BUT, no mail is sent from the GAE project.

Thanks, hope someone has an answer.

1条回答
Explosion°爆炸
2楼-- · 2019-09-05 08:47

Thanks to the guys at sendgrid-python this issue is resolved, with an update to sendgrid-python.

4 steps:

  • 'pip install sendgrid'
  • 'pip install smtpapi'
  • copy sendgrid folder and smtpapi folder into your GAE directory
  • move smtpapi folder into sendgrid folder - example code from github sendgrid-python now executes correctly and how you have sendgrid functionality for GAE.

Hope this helps someone.

查看更多
登录 后发表回答