I'm a new user of python. I don't know why but requests always throws an InvalidURL exception:
>>> import requests
>>> r = requests.get('https://www.google.es/')
The output:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 380, in prepare_url
scheme, auth, host, port, path, query, fragment = parse_url(url)
File "/usr/lib/python3/dist-packages/urllib3/util/url.py", line 392, in parse_url
return six.raise_from(LocationParseError(source_url), None)
File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: https://www.google.es/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 516, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 459, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 314, in prepare
self.prepare_url(url, params)
File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 382, in prepare_url
raise InvalidURL(*e.args)
requests.exceptions.InvalidURL: Failed to parse: https://www.google.es/
This error is independent of the url I give. How do I handle this?
The version of Python is 3.7.7 and 2.23.0 for requests.
Best regards.
You faced Error due to the New version of urllib3 (some users tends to face this issue).
The error is not due to requests but issue is rather in urllib3 (new ver) that gets installed when installing requests 2.21.0+.
To avoid this either try updating urllib3:
python -m pip install --upgrade urllib3
or install the requests v2.21.0:
pip uninstall requests # to remove current version
pip install requests==2.21.0
Just downgrade it to v2.21.0 version
See if you have a hidden character in your URL.
I've wasted tons of time and that was the problem..
this can happen when you copy-paste the URL from somewhere.
it's happen sometimes when the URL is not the valid one. I have this error and after hours found that I have a small spaces between each / on the URL...
so I suggest to write the URL again on requests.get for no get this mistake..
Related
When searching or installing packages with pip on MacOS (10.11.6), I am getting an SSL error similar to the one reproduced below.
The problem occurs for both python2 and python3. I acquired the versions (2.7.14 and 3.6.5) via www.python.org as Frameworks. The version of pip was 9.0.1. The problem is new (April 2018) and seems related to an update of OSX.
How to recover from this problem?
$ pip2 search numpy
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 45, in run
pypi_hits = self.search(query, options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 62, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1243, in __call__
return self.__send(self.__name, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1602, in __request
verbose=self.__verbose
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 775, in request
headers=headers, stream=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 522, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)
There are two ways to recover from this problem.
Solution 1. As can be read here, Python.org sites stopped the support for older TLS versions, which breaks pip < 9.0.3. A new release of pip was provided, but because one cannot simply update via the broken pip, one has to bootstrap the installation. This worked for me:
# For python2
curl https://bootstrap.pypa.io/get-pip.py | python2
# For python3 (haven't tested this myself)
curl https://bootstrap.pypa.io/get-pip.py | python3
Credits for these commands go back to this SO post.
Solution 2. For Python 3.6 frameworks, a script Install Certificates.command is deployed and installed under /Applications/Python 3.6/. Executing it resolved the problem, but only for pip3.
You just need to reinstall Python
brew reinstall python
This image will help you to find the issue I have configured Openstack newton on ubunu 16.04 LTS. It works fine
Now i have planned to integrate Murano in to this.
All progressed fine..When i am running dashboard using "tox -e venv -- python manage.py runserver <IP:PORT>" command. I am able to run the murano dashboard.
When i am accessing environment tab it displaying error
Error: There was an error communicating with server.
And log message displays an error
No module named memcache
For your reference error message below:
Traceback (most recent call last):
File "/root/murano/murano/murano/api/middleware/fault.py", line 130, in
process_request
return req.get_response(self.application)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/webob/request.py",
line 1299, in send
application, catch_exc_info=False)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/webob/request.py",
line 1263, in call_application
app_iter = application(self.environ,
start_response)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/webob/dec.py",
line 130, in __call__
resp = self.call_func(req, *args,
**self.kwargs)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/webob/dec.py",
line 195, in call_func
return self.func(req, *args, **kwargs)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 320, in __call__
response = self.process_request(req)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 552, in process_request
resp = super(AuthProtocol,
self).process_request(request)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 348, in process_request
data, user_auth_ref =
self._do_fetch_token(request.user_token)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 388, in _do_fetch_token
data = self.fetch_token(token)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 661, in fetch_token
cached =
self._cache_get_hashes(token_hashes)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/__init__.py",
line 644, in _cache_get_hashes
cached =
self._token_cache.get(token)
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/_cache.py",
line 214, in get
with self._cache_pool.reserve() as cache:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/root/murano/murano/.tox/venv/local/lib/python2.7/site-packages/keystonemiddleware/auth_token/_cache.py",
line 78, in reserve
import memcache
ImportError: No module named memcache
Can someone help on this?
Thanks in Advance.
Just installing memcached is not enough. You will also need to install python memcache module which is provided separately by python-memcache and python-pymemcache. I am not sure which one is used here.
You can try installing them with apt-get and see which one works for you.
Now working.. I have installed murano api and murano dashboard in different venv.
I have missed to install memcache in munano api venv. When i'm tried after install memcache in murano api venv..Now working fine..
#tutuDajuju Thanks for the Help...
I am trying to use pip from virtual enviroment on Linux Ubuntu 14.04 x64.
While using pip from shell as:
pip search bla
it works fine.
But using from virtualenv it shows error:
(proj_testing)uxu#box:~$ pip search bla
/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Exception:
Traceback (most recent call last):
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/commands/search.py", line 43, in run
pypi_hits = self.search(query, options)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/commands/search.py", line 60, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/usr/lib/python2.7/xmlrpclib.py", line 1233, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1587, in __request
verbose=self.__verbose
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/download.py", line 785, in request
headers=headers, stream=True)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 508, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/download.py", line 373, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/home/uxu/.virtualenvs/proj_testing/local/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
It doesn't make sense, anyone got idea?
Try execute pip search bla like superuser
For ubuntu the command is:
sudo pip search bla
From https://urllib3.readthedocs.org/en/latest/security.html:
Certain Python platforms (specifically, versions of Python earlier than 2.7.9) have restrictions in their ssl module that limit the configuration that urllib3 can apply. In particular, this can cause HTTPS requests that would succeed on more featureful platforms to fail, and can cause certain security features to be unavailable. If you encounter this warning, it is strongly recommended you upgrade to a newer Python version, or that you use pyOpenSSL as described in the OpenSSL / PyOpenSSL section.
You probably have a less recent version of python in your virtual environment. Perhaps this is why this error only occurs in the virtual environment.
I'm a begginer in Python and have been struggling with downloading a file using the package requests. My code works for an url with http, but not for https. The code is the following:
import requests
url = 'https://firms.modaps.eosdis.nasa.gov/active_fire/shapes/zips/Central_America_24h.zip'
print "downloading with requests"
r = requests.get(url)
with open("Central_America_24h.zip", "wb") as code:
code.write(r.content)
I get the following errors:
Warning (from warnings module):
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 90
InsecurePlatformWarning
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
Traceback (most recent call last):
File "C:\Users\lmixco\Downloads\descarga.py", line 8, in <module>
r = requests.get(url)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\api.py", line 68, in get
return request('get', url, **kwargs)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 594, in send
history = [resp for resp in gen] if allow_redirects else []
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 196, in resolve_redirects
**adapter_kwargs
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: [Errno 8] _ssl.c:503: EOF occurred in violation of protocol
I have been looking for a solution, but have not found anything. Any help will be appreciated. Thanks in advance.
you need to install a package , use this
pip install requests[security]
for debain / ubuntu , install this before installing above package
apt-get install python-dev libffi-dev libssl-dev
i can't use django-socketio, i get this error:
AttributeError: 'SocketIOHandler' object has no attribute 'response_headers_list'
Terminal:
Traceback (most recent call last):
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/server.py", line 49, in handle
handler.handle()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/pywsgi.py", line 184, in handle
result = self.handle_one_request()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/pywsgi.py", line 321, in handle_one_request
self.handle_one_response()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/handler.py", line 58, in handle_one_response
self.handle_one_response(call_wsgi_app=False)
TypeError: handle_one_response() got an unexpected keyword argument 'call_wsgi_app'
<Greenlet at 0x10247ac30: <bound method SocketIOServer.handle of <SocketIOServer at 0x1028ce8d0 fileno=5 address=127.0.0.1:8000>>(<socket at 0x102976210 fileno=[Errno 9] Bad file d, ('127.0.0.1', 51457))> failed with TypeError
Traceback (most recent call last):
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/server.py", line 49, in handle
handler.handle()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/pywsgi.py", line 184, in handle
result = self.handle_one_request()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/gevent/pywsgi.py", line 321, in handle_one_request
self.handle_one_response()
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/handler.py", line 68, in handle_one_response
jobs = self.transport.connect(session, request_method)
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/transports.py", line 92, in connect
self.write_packed(session_id)
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/transports.py", line 19, in write_packed
self.write(data)
File "/Volumes/DATA/Projekti/virtualenv/caffetouch/lib/python2.7/site-packages/socketio/transports.py", line 22, in write
if 'Content-Length' not in self.handler.response_headers_list:
AttributeError: 'SocketIOHandler' object has no attribute 'response_headers_list'
<Greenlet at 0x10247ac30: <bound method SocketIOServer.handle of <SocketIOServer at 0x1028ce8d0 fileno=5 address=127.0.0.1:8000>>(<socket at 0x102976210 fileno=[Errno 9] Bad file d, ('127.0.0.1', 51460))> failed with AttributeError
I think this is showing becouse it isn't supported with new django, or something like this.
Any solution?
Hope it won't be too late. It's actually a compatibility issue. You need to uninstall some newer packages. See here.
Here is part of my configuration. It works.
$ pip list
Django (1.6.7)
django-socketio (0.3.8)
gevent (0.13.6)
gevent-socketio (0.2.1)
gevent-websocket (0.2.3)
greenlet (0.4.5)
pip (1.5.6)
setuptools (6.0.2)
sphinx-me (0.3)
If you are using django 1.8 or above then you need to uninstall new version and install the previous version using the given command:
pip install django-socketio==0.3.9
pip uninstall gevent-socketio gevent
pip install gevent-socketio==0.2.1 gevent==0.13.6
For more details, see the following thread: https://github.com/stephenmcd/django-socketio/issues/63