I'm trying to use boto3 for Polly API in Google App Engine for Python. So far, I've installed boto3 in my lib subdirectory
pip install -t lib boto3
When I run a standalone script it runs well But when I execute boto3.client(...) in my app on my DEV server, I get an error coming from the botocore/session.py:
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
ImportError: No module named _winreg
I have seen that as GAE is sandboxed so it is normal that _winreg module is unavailable
Does anyone has the experience of installing boto3 on GAE and have it run on DEV and PROD server?
Or is there another way to use the Polly API?
As answered by @simon-pierre below the _winreg error can be solved by editing the config_appengine.py and adding :
import sys
sys.plateform='linux3'
But then I runned in another problem
Python NameError: global name 'ssl' is not defined. To solve this one, you have to edit app.yaml and enable ssl through :
libraries:
- name: ssl
version: 2.7.11
And then come another problem which is specific to GAE on Windows : from _ssl import RAND_egd makes an ImportError: cannot import name RAND_egd. In sochet.py
A modification of socket.py described below can solve it : https://code.google.com/p/googleappengine/issues/detail?id=12783
And then comes an ultimate problem that I haven't found a fix for now :
On DEV server, AWS answers : ConnectionError: ('Connection aborted.', error(13, 'Permission denied')) to my call client.describe_voices('en-US') when called from DEV GAE but not when the same script is called standalone.
I have found a reference to this kind of problem with the PayPal SDK and a solution for PayPal but does anyone has a solution for AWS boto3
https://github.com/paypal/PayPal-Python-SDK/issues/66
Any idea?
Workaround: in your appengine_config.py file, change the sys.platform
value:
import sys
sys.platform = 'linux3'
The problem is the App Engine development environment is sandboxed and blocks the use of the _winreg
module. (Source: https://stackoverflow.com/a/28653565/902751)
According to this comment from the App Engine Google Group,
With Python version >= 2.7.4, sys.platform is not explicitly set to 'linux3' in the dev_appserver sanbox environment in Windows since App Engine SDK >= 1.9.34. [...] Unfortunately, the original sandbox.py code of sys.platform = 'linux3' was in place for compatibility with older systems.