pycrypto and Google App Engine on windows 10 - google-app-engine

I'm trying to run pycrypto (2.6) on google app engine (1.9.32) with python 2.7 on windows 10.
I've added the following to my app.yaml:
libraries:
- name: pycrypto
version: "2.6"
and added the following config:
import os
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
But I'm still getting the following error:
The Python egg cache directory is currently set to:
/tmp
Perhaps your account does not have write access to this directory?
You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
pycrypto works fine on windows 10 in python command line. The problem is just in the Google app engine.
How is it possible to work around this?
2 side notes:
The phenomenon is known as the Python egg error.
Windows 10 folder locking in read-only is documented. No solutions seemed to work so far.

Related

Why does my Google App Engine app use an old version of OpenSSL?

I have
libraries:
- name: ssl
version: latest
In my app.yaml file
I print out
print(ssl.OPENSSL_VERSION)
In my main.py file, which is a flask app. When I run main.py using python, the program prints out
'OpenSSL 1.1.0h 27 Mar 2018'
But when I run the app using dev_appserver.py, it prints out
OpenSSL 0.9.8zh 14 Jan 2016
Why is it using an older version of open ssl? I think this is leading to this error that I get when I try to send a message using Twilio
TwilioRestException: HTTP 426 error: Unable to create record: Upgrade Required
I'm not sure, but I think the gcloud tools don't install any version of OpenSSL on your computer, and instead use the version of OpenSSL that is already there as part of your existing Python installation.
The version of OpenSSL used with dev_appserver.py thus wouldn't be the same one that is used in production.
The difference between main.py and dev_appserver.py is likely caused by different different path configurations. Those two versions of OpenSSL are somewhere on your computer and the path configuration picks up one versus the other.
Best way to check is to log the OpenSSL version in your production environment.

Why am I getting: EventError: libraries entries only supported by python27 runtime? when running GAE

I'm running a local development copy of Google AppEngine PHP SDK v1.8.0, with PHP v5.4.3 and Python v2.7, all under Windows 7 64bit.
I have followed instructions from a number of posts both here and elsewhere in order to register Python with my OS and to properly install the Python PIL module.
The last post I found here Unable to find the Python PIL library.Google App Engine. I have therefore added :
libraries:
- name: PIL
version: 1.1.7
to app.yaml.
I now receive the error quoted in the title of this post. If anyone can advise, I would be grateful.
Thankyou.
I think what #Tim was trying to say is that you should change your app.yaml to say "runtime: python27" instead of "runtime: php" since, as the error suggests, the PIL library is only supported by python27, not php.

Trouble with Google appengine id

I successfully launched an app locally on the local host
When I deployed to the appengine I got an error.
com.google.appengine.tools.admin.HttpIoException: Error posting to URL: https://appengine.google.com/api/appversion/create?app_id=my_id&version=1&
404 Not Found
This application does not exist (app_id=u'my_id').
For some reason the ID given in the error has u and a space appended in the beginning
I doubled checked the application exists and succesfuly uploaded the app from another computer
All the solutions I can find (like "This application does not exist (app_id=xxx)", or "GAE - Deployment Error: “AttributeError: can't set attribute”") mention running appcfg.py with the --no_cookies
C:\Program Files (x86)\Google\google_appengine\appcfg.py
appcfg.py --no_cookies update my-app-folder\
# or (2-steps verificatio enabled)
appcfg.py --oauth2 --no_cookies update my-app-folder\
If the project contains Java7 classes, you need to add the --use_java7 option, as shown in the question "Failed to deploy to Google App Engine because --use_java7 flag has not been set".
While you can run appcfg from the GAE installation path, the page "Using the Google Plugin for Eclipse" mentions (at the bottom of the page):
Some features of the App Engine Java SDK tools are only available by running the tools directly from the command line. If you have installed the SDK using Eclipse, you can run these tools from the Eclipse plugin installation directory.
The SDK is located in your Eclipse installation directory, under plugins/com.google.appengine.eclipse.sdkbundle_VERSION/, where VERSION is a version identifier for the SDK.
In this directory is the appengine-java-sdk/bin/ subdirectory containing the tools.

"ImportError: No module named _ssl" with dev_appserver.py from Google App Engine

Background
"In the Python runtime, we've added support for the Python SSL
Library, so you can now open secure connections to remote services
such as Apple's Push Notification service."
This quote is taken from a recent post on the Google App Engine blog.
Implementation
If you want to use native python ssl, you must enable it using the libraries configuration in your application's app.yaml file where you specify the library name "ssl" . . .
These instructions are provided for developers through the Google App Engine documentation.
The following lines have been added to the app.yaml file:
libraries:
- name: ssl
version: latest
This much is in line with the advice provided through the Google App Engine documentation.
Problem
I have tried running my project in three different configurations. Two are working, and one is not.
Working ...
After I upload my application to Google App Engine, and run my project through the live server, everything works fine.
Working ...
When I run my project with manage.py runserver and include the Google App Engine SKD in my PYTHONPATH, everything works fine.
Not Working ...
However, when I run my project with dev_appserver.py, I get the following error:
ImportError at /
No module named _ssl
Request Method: GET
Request URL: http://localhost:8080/
Django Version: 1.4.3
Exception Type: ImportError
Exception Value:
No module named _ssl
Exception Location: /usr/local/lib/google_appengine_1.7.7/google/appengine/tools/devappserver2/python/sandbox.py in load_module, line 856
Python Executable: /home/rbose85/Code/venvs/appserver/bin/python
Python Version: 2.7.3
Python Path:
['/home/rbose85/Code/product/site',
'/usr/local/lib/google_appengine_1.7.7',
'/usr/local/lib/google_appengine_1.7.7/lib/protorpc',
'/usr/local/lib/google_appengine_1.7.7',
'/usr/local/lib/google_appengine_1.7.7',
'/usr/local/lib/google_appengine_1.7.7/lib/protorpc',
'/usr/local/lib/google_appengine_1.7.7',
'/usr/local/lib/google_appengine_1.7.7/lib/protorpc',
'/home/rbose85/Code/venvs/appserver/lib/python2.7',
'/home/rbose85/Code/venvs/appserver/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/local/lib/google_appengine',
u'/usr/local/lib/google_appengine_1.7.7/lib/django-1.4',
u'/usr/local/lib/google_appengine_1.7.7/lib/ssl-2.7',
u'/usr/local/lib/google_appengine_1.7.7/lib/webapp2-2.3',
u'/usr/local/lib/google_appengine_1.7.7/lib/webob-1.1.1',
u'/usr/local/lib/google_appengine_1.7.7/lib/yaml-3.10']
Server time: Wed, 24 Apr 2013 11:23:49 +0000
For the current GAE version (1.8.0 at least until 1.8.3), if you want to be able to debug SSL connections in your development environment, you will need to tweak a little bit the gae sandbox:
add "_ssl" and "_socket" keys to the dictionary _WHITE_LIST_C_MODULES in /path-to-gae-sdk/google/appengine/tools/devappserver2/python/sandbox.py
Replace the socket.py file provided by google in /path-to-gae-sdk/google/appengine/dis27 from the socket.py file from your Python framework.
IMPORTANT: Tweaking the sandbox environment might end up with functionality working on your local machine but not in production (for example, GAE only supports outbound sockets in production). I will recommend you to restore your sandbox when you are done developing that specific part of your app.
The solution by jmg works, but instead of changing the sdk files, you could monkey patch the relevant modules.
Just put something like this on the beginning of your project setup.
# Just taking flask as an example
app = Flask('myapp')
if environment == 'DEV':
import sys
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']
from lib import copy_of_stdlib_socket.py as patched_socket
sys.modules['socket'] = patched_socket
socket = patched_socket
I had to use a slightly different approach to get this working in CircleCI (unsure what peculiarity about their venv config caused this):
appengine_config.py
import os
if os.environ.get('SERVER_SOFTWARE', '').startswith('Development'):
import imp
import os.path
import inspect
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']
# Use the system socket.
real_os_src_path = os.path.realpath(inspect.getsourcefile(os))
psocket = os.path.join(os.path.dirname(real_os_src_path), 'socket.py')
imp.load_source('socket', psocket)
I had this problem because I wasn't vendoring ssl in my app.yaml file. I know the OP did that, but for those landing here for the OP's error, it's worth making sure lines like the following are in your app.yaml file:
libraries:
- name: ssl
version: latest
Stumbled upon this thread trying to work with Apples Push notification service and appengine... I was able to get this working without any monkey patching, by adding the SSL library in my app.yaml, as recommended in the official docs, hope that helps someone else :)
I added the code to appengine_config.py as listed by Spain Train, but had to also add the following code as well to get this to work:
phttplib = os.path.join(os.path.dirname(real_os_src_path), 'httplib.py')
imp.load_source('httplib', phttplib)
You can test if ssl is available at your local system by opening a python shell and typing import ssl. If no error appears then the problem is something else, otherwise you don't have the relevant libraries installed on your system. If you are using a Linux operating system try sudo apt-get install openssl openssl-devel or the relevant instructions for your operating system to install them locally. If you are using windows, these are the instructions.

ImportError while running Google App Engine test project

I am new to Google App Engine and so, I just followed the procedure to test an application which just prints "hello world".
(followed according to Google App Engine Documentation)
The project folder name is "GoogleApp"
This is my Python file:
File Name : sayHello.py
#!/usr/bin/env python
def main():
print "hello"
pass
if __name__ == '__main__':
main()
This the yaml file
File Name : app.yaml
application: GoogleApp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: sayHello.py
When ever I just run the project in Google App Engine Launcher, this is the log error I am getting
2012-04-19 10:52:23 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8080', 'D:\\Code\\Projects\\IRCmathBot\\GoogleApp']"
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 125, in <module>
run_file(__file__, globals())
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 121, in run_file
execfile(script_path, globals_)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_main.py", line 157, in <module>
from google.appengine.tools import appcfg
File "C:\Program Files\Google\google_appengine\google\appengine\tools\appcfg.py", line 41, in <module>
import mimetypes
File "C:\Python27\lib\mimetypes.py", line 29, in <module>
import urllib
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
2012-04-19 10:52:25 (Process exited with code 1)
Actually, I use Python 2.7. The above log says that python25.dll conflicts with version of python.
I don't know what exactly it means but I could interpret that
It should either support only python 2.5 or
It I should have used python 2.5 code.
as the 2nd isn't possible and Google supports 2.7, I don't know what is this error.
Try to figure out myself but couldn't succeed.
I had a very similar problem (while running the tutorial code), and solved it by checking my PythonPath system environment variable.
For me, OpenCV edited the PythonPath variable to point to its own directory structure instead of the base Python installation itself.
You can edit the environment variables by opening up the 'Advanced System Properties' window and clicking on the 'Environment Variables' button. The 'PythonPath' variable under 'System Variables'. At the minimum, it should include the path of your python executable, such as 'C:\Python27\'.
Have you tried in command-line? Forget the launcher.
I had same problem! I re-installed Python several times, changed versions. It was hilarious.
With version 2.5 launcher can start the server, but the application doesn't work, but I can upload it online through launcher.
With Python ver. 2.7, launcher displays same problems you're dealing with. I also can't get the server started locally. But command-line works well, both starting the server locally and uploading online.
So I'll stick with version 2.7. Hope it helps, let me know..
You have threadsafe enabled, so you should use WSGI handlers. That could be the problem. I would replace your code with the following:
File: helloworld.py
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, WebApp World!')
app = webapp2.WSGIApplication([('/', MainPage)])
File: app.yaml
application: GoogleApp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
If using Python2.7 on Google AppEngine, refer to this official documentation to create your first "Hello World" Application.
I fixed this after 3 hrs of effort. Reinstall cannot solve my problem, messing around the user/system environment variable also not work.
Follow this step work:
Open Google Drive Perference, turn off auto run after win start up
turn off Google Drive
or simply uninstall google drive (Google Drive seems using Python 2.5 _socket library
uninstall python and GAE
reboot
install python27 and GAE
Most importantly, specify a new path, do not use the default c:\python27 again (I changed it to c:\mypython27. same as GAE, use a new path.
Then it works again.
Something's seriously broken with your Python 2.7 installation - parts of it are referencing Python 2.5 libraries. You should uninstall all versions of Python on your machine, and reinstall the version(s) you need.
I guess you've added the GAE path into the environment variable PATH? Just remove it.
I had exactly the same problem with you, it seems to me that Python 2.7 will try to use an incorrect _socket.pyd lib under GAE path, removing GAE path from PATH will fix this.
It needs no extra coding, just a tiny configuration of your win OS.
Since my OS language is Chinese, names of icons/links below are translated from Chinese by myself, which i cannot guarantee to be correct :(
Right click on the "Computer" icon, choose 'Properties', you'll see the system panel showing some basic system information;
Click on the "Advanced System Settings" link, you'll see the system property panel containing several tabs;
Choose the "Advanced" tab, there should be a button named "Environment variables" on the bottom, click on it then you can see a dialog displaying all environment variables of your system;
Find and edit the variable named "PATH" or "Path" (case insensible): if its value contains a path to your GAE, then remove the GAE path.
For me it was that I did set the System Variable PYTHONPATH to '.'. Deleting the variable did the job!
I set PYTHON_PATH to
"C:\Program Files\Google\google_appengine;C:\Program
Files\Google\google_appengine\lib\antlr3;C:\Program
Files\Google\google_appengine\lib\django_0_96;C:\Program
Files\Google\google_appengine\lib\fancy_urllib;C:\Program
Files\Google\google_appengine\lib\graphy;C:\Program
Files\Google\google_appengine\lib\ipaddr;C:\Program
Files\Google\google_appengine\lib\simplejson;C:\Program
Files\Google\google_appengine\lib\webob;C:\Program
Files\Google\google_appengine\lib\yaml\lib"
but then I realize that django 0.96 require python 2.5, so use django 1.4, and it works fine.
"C:\Program Files\Google\google_appengine;C:\Program
Files\Google\google_appengine\lib\antlr3;C:\Program
Files\Google\google_appengine\lib\django-1.4;C:\Program
Files\Google\google_appengine\lib\fancy_urllib;C:\Program
Files\Google\google_appengine\lib\graphy;C:\Program
Files\Google\google_appengine\lib\ipaddr;C:\Program
Files\Google\google_appengine\lib\simplejson;C:\Program
Files\Google\google_appengine\lib\webob;C:\Program
Files\Google\google_appengine\lib\yaml\lib"
If you have same problem as above, just check PATH, PYTHON_PATH to see whether mismatch version between library and python. Hope this help.
Some programs may modify the PYTHONPATH environment variable. If you check it's value (System -> Environment variables) and ensure it is set to the correct python 2.7 path (default C:\Python27) then this should fix the issue. In my case something had set it to my google appengine path.
ImportError: Module use of python25.dll conflicts with this version of Python.
The problem is that python25.dll conflicts with your Python 2.7 installation. This python25.dll comes from the greatly outdated Google App Engine Launcher for Windows and is located in C:\Program Files\Google\google_appengine\launcher
It is not a problem of your Python 2.7 install - it is a problem of Launcher, who injects its own Python path into app environment. To test that, add the following lines at the top of google_appengine/dev_appserver.py after first imports:
from pprint import pprint
pprint(sys.path)
Then re-run you app to get fresh log and see for yourself:
...
'C:\\OpenCV2.3\\opencv\\build\\python\\2.7',
'C:\\Google\\google_appengine\\launcher',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
...
I got the launcher from Python .msi SDK 1.8.8, and it is of course suxx that Google still ships several versions of SDK with broken GUI tool. To fix that, add the following after first imports in dev_appserver.py:
# --- Repair sys.path after broken GAE Windows Launcher
# see http://stackoverflow.com/questions/10222342/
ROOT = os.path.abspath(os.path.dirname(__file__))
LAUNCHPATH = os.path.join(ROOT, 'launcher')
if LAUNCHPATH in sys.path:
sys.stderr.write('[BUG] GAE Windows Launcher detected. Fixing..\n')
sys.path.remove(LAUNCHPATH)
# /--
Unfortunately, you'll need to repeat the procedure when new version of GAE comes out. There is an issue #8568 on AppEngine tracker that you can star and comment to make it fixed someday.
Do you have a PYTHONPATH variable in Environment Variables? delete it and restart the Google App Engine Launcher,it will work!

Resources