Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import sendgrid into GAE application

I have a GAE application that I want to integrate with Sendgrid. I've followed the instructions (https://cloud.google.com/appengine/docs/python/mail/sendgrid) on how to install Sendgrid and everything works fine in my local dev environment.

However, when I push my application to GAE and run it, I immediately receive the following 500 Server Error:

Error: Server Error

The server encountered an error and could not complete your request. Please try again in 30 seconds.

Even with debug on, that's all I get. But digging into the logs at GAE I can see the source of the problem:

Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject obj = ____import____(path[0]) File "/base/data/home/apps/....wsgi_app.py", line 16, in import sendgrid File "/base/data/home/apps/..../sendgrid/____init____.py", line 7, in from .client import SendGridAPIClient File "/base/data/home/apps/..../sendgrid/client.py", line 1, in import python_http_client ImportError: No module named python_http_client

So I went into sendgrid/client.py and commented out the following line of code...

import python_http_client

Once I do that, I can run my app without receiving the 500 Server Error but the test email I tried to send wasn't delivered (although I didn't receive any error messages when trying to initiate it).

It doesn't seem right that I need to comment out a line of the Sendgrid code to make the import work and I can't figure out why others that are running Sendgrid with Python and GAE aren't having the same problem. Any thoughts would be appreciated. Thanks.

like image 894
dsedwards Avatar asked Mar 08 '16 23:03

dsedwards


1 Answers

sendgrid does need python_http_client, which Sendgrid itself maintains at https://github.com/sendgrid/python-http-client -- just copy the few files in directory https://github.com/sendgrid/python-http-client/tree/master/python_http_client to a directory named python_http_client, making the latter a sibling of the sendgrid directory. I'm not sure why the online docs don't mention that -- I'll work to get it fixed, but meanwhile I hope this workaround lets you get started.

like image 191
Alex Martelli Avatar answered Sep 29 '22 11:09

Alex Martelli