Python Appengine - "ImportError: cannot import name OSRNG" when invoking the Endpoints tool - python-2.7

I am following this tutorial on Google Cloud Endpoints. I am having trouble at the "Generating the OpenApi configuration file" section. Specifically, when I invoke the Endpoints tool.
The Traceback is saying that the file on lib/Crypto/Random/init.py "from Crypto.Random import OSRNG" is producing the import error.
What I have done so far
Looked at the path lib/Crypto/Random and saw a folder named OSRNG - thus made sure that there was a folder called OSRNG (I didnt see any py file name OSRNG.py though)
Followed the answer for this question by putting the pycrypto version to "latest" in the app.yaml file.
Looked into this question but doesnt apply.
Looked into this question by specifying the version rather than "latest" in app.yaml.
I don't understand why it is saying there is an import error when I can literally see the package/module in the directory.
Can someone help why it is producing an import error?

Are you running on OSX?
I encountered a similar problem and the solution for me was installing google-endpoints (which for some reason is missing from the instructions):
pip install -t lib google-endpoints --ignore-installed

Related

Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

It's the first time I work with django rest and Django Oauth toolkit
I'm following this tutorial
oauth2-with-django-rest-framework
But when I run python manage.py migrate I get the following error:
ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.
What is going wrong ? is there another module I should install ?
my virtual environment contains :
certifi==2017.4.17
chardet==3.0.4
Django==1.11.2
django-extensions==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
requests==2.18.1
six==1.10.0
Unidecode==0.4.21
urllib3==1.21.1
It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
to:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
Note that the tutorial is a couple of years old, you might find other problems like this.
I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
I just installed older version as #Alasdair ask. My issue resolved. thanks

Unable to run setup.py behind proxy

I'm new to python (and linux) and I'm trying to run the setup.py, however it's not working properly because there's a corporative proxy blocking te request to pypi.
I check this link to properly use the setup.py and also check this and this solutions in stackoverflow but I can't make them work (or I'm wrong in the way I'm applying them).
I'm using:
virtualenv
virtualenvwrapper
python 2.7
Ubuntu 14
I already add the http_proxy and https_proxy in .profile and .bashrc.
When I use pip install --proxy the.proxy:port some_module it's working properly (also I know the env variables do something is because before that I can't even get to stackoverflow.com, so I'm assuming they work just fine).
What I have already tried is:
Trying to use --proxy on python
Look for something similar to --proxy in python
Trying to add the proxy configuration described in one of the solutions mentioned earlier in my setup.py (which is add to the description of this problem)
Tried and successfully downloaded a couple of modules with pip --proxy (this is my current not-so-good-solution)
Messing with the python configuration files in the virtualenv in hope of find some proxy config
My setup.py file looks like this:
from setuptools import setup, find_packages
import requests
with open('development.txt') as file:
install_requires = file.readlines()
with open('development_test.txt') as file_test:
test_requires = file_test.readlines()
setup(
name="my_project",
version="1.0.0-SNAPSHOT",
packages=find_packages(),
install_requires=install_requires,
test_suite="nose.collector",
tests_require=test_requires,
)
proxies = {
"http": "http://proxy.myproxy.com:3333",
"https": "http://proxy.myproxy.com:3333",
}
# not sure what goes here... tried a few things but nothing happend
requests.get("https://pypi.python.org", proxies=proxies)
I'll try any suggestion, any help appreciated.
Thanks
After a deep search about how python works and not being able to find the problem I start looking to how the bash commands work.
It turn out you have to export the http_proxy variables with sudo -E.
A rocky mistake.

GAE import endpoints "No module named endpoints"

I'm using pycharm to develop appengine. Now i'm trying to use endpoints and I've put
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
and then in main.py
import endpoints
But it gives me error
No module named endpoints
I can see the endpoints folder inside the GAE library. Anyone can help?
*EDIT: it is just a matter of IDE (pycharm) cant locate endpoints. The app runs fine and okay both in dev server or cloud server. There is a picture just to make it a bit clearer:
Thanks
You need to add {GAE_SDK}/lib/endpoints-1.0, not just the SDK itself. The reason you can import google is because it is directly under {GAE_SDK}. The libraries you specify in app.yaml are laid out differently due to supporting multiple versions. I believe you also need to add {GAE_SDK}/lib/protorpc-1.0/, it's just not showing because there's already an import error.
I'm using the new version of PyCharm Community and I got to config too. You need to set the Source option on each folder like endpoints in File - Setting - Project:
I've run across the following code somewhere which fixes it for me in a client script. I'm not able to say how much of it may be unnecessary. You'd need to edit the google_appengine path for your SDK installation:
sdk_path = os.path.expanduser('~/work/google-cloud-sdk/platform/google_appengine')
try:
import google
google.__path__.append("{0}/google".format(sdk_path))
except ImportError:
pass
try:
import protorpc
protorpc.__path__.append("{0}/lib/protorpc-1.0/protorpc".format(sdk_path))
except ImportError:
pass
sys.path.append("{0}/lib/endpoints-1.0".format(sdk_path))

Import error web "no module named web"

I did an web application using web.py and after a while I realize that my python compiler was configure to use python2 instead of python3 (both are installed). With python2 my application was working but I got string in unicode so I try to execute my code using python3:
python3 mycode.py
But I get different kind of error, the lib urlparse was not found (this problem was cause by a new name in python3 which is urllib) but I got a problem with:
import web
The return error is:
ImportError: No module named 'web'
I can't figure out where the problem come from.
Web.py cannot work with python3, this is the linked to the gitub project.
https://github.com/webpy/webpy/issues/108
Maybe you have installed web in your python2 lib but you have none in python3 lib... Check it out

why I am Getting Import error for eve.io.SQLAlchemy?

I am running the demo script available at
https://gist.github.com/Tefnet/5430309
I am getting following error, despite having all libraries
flask sqlalchemy validate SQL
File demo.py in line 2 , in <module>
from eve.io.sqlalchemy import SQLAlchemy, Validator
ImportError no module named sqlalchemy
Not sure why is it giving ? even though I have installed EVE, SQLAlchemy, flask
The SQLAlchemy branch is a work in progress. It has evolved quite a bit from the fork linked by codegeek and now is almost on par (feature-wise) with v0.4dev.
Eve-SQLAlchemy branch
So if you want to play around with it, make sure to pull that branch. Also, one thing it's not been done yet is update requirements.txt and setup.py, so you will want to pip install sqlalchemy on your own.
You can find a rather complete Eve-SQL log by checking out this very long lived ticket.
There is no eve.io.sqlalchemy by looking at the official source code of eve. The Gist that you are looking at is a fork from eve but the changes are not pulled in yet officially.
See the commit changes here.