I want to use the requests
module in Google App Engine Python Standard Runtime Environment.
Quote from official Google Cloud docs:
You can use third-party libraries that are pure Python code with no C extensions, by copying the library into your application directory. If the third-party library is already built-in, bundled with the runtime, you can use the library without copying it into your app.
Third party libraries must be implemented as pure Python code with no C extensions. If copied to your application directory, they count towards file quotas because the library is uploaded to App Engine along with your application code.
requests
isn't bundled with GAE, so I added it into my application folder according to the instructions.
requests
required a few other modules that don't come with GAE, so I added all of them to my application folder:
certifi
chardet
idna
urllib3
Another problem came up. My request goes to the Stack Exchange API, which has the https://
protocol. Here's the error:
SSLError: HTTPSConnectionPool(host='api.stackexchange.com', port=443): Max retries exceeded with url: /2.2/1?site=stackoverflow (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))
The ssl
module is built into the GAE Python runtime, so I put the following in app.yaml
:
libraries:
- name: webapp2
version: latest
- name: ssl
version: latest
It didn't work. I got the same error as before. I copied the SSL module folder into my application directory and did import ssl
in main.py
, but now it throws an exception asking for yet another module to be installed:
File "/Users/williamqin/Projects/stackpromo/ssl/__init__.py", line 61, in <module>
import _ssl2 # if we can't import it, let the error propagate
ImportError: No module named _ssl2
I searched all over the web for the _ssl2
Python module, but I couldn't find it anywhere!
How do I properly use the requests
module in Google App Engine?