The requests package in Python seems to reference the incorrect SSL cert in Ubuntu. I'm using requests 2.6.2. The code runs fine on a Mac but fails on Ubuntu. I appreciate any help!
This request:
query_string = https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0
requests.get(query_string, auth=(self.accessid,self.key))
Produces this error output:
Traceback (most recent call last):
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
requests.get('https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0')
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: hostname 'lsapi.seomoz.com' doesn't match either of 'incapsula.com', ...
This question boils down to being the same as this one: the version of Python you're using does not support SNI. Follow the advice in this answer.
Related
I'm trying to connect to a website with a proxy. But when I use the code below I get an error. I tried changing http to https. I tried different proxies. But non of them solved my issue.
import requests
proxies = {"http": "http://91.93.135.113:8080"}
requests.get("http://ifconfig.me/ip", proxies=proxies).content
Output:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 412, in send
conn = self.get_connection(request.url, proxies)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 305, in get_connection
proxy_url = parse_url(proxy)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-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: http://46.197.209.217:3128
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 414, in send
raise InvalidURL(e, request=request)
requests.exceptions.InvalidURL: Failed to parse: http://46.197.209.217:3128
Try using Burp Proxy!
I just change Burp Options on Proxy Label to bind all interfaces (0.0.0.0) and it works with your code.
import requests
response = requests.post('https://api.github.com/user/repos')
Simple code just to test that requests are working.
I get the following errors.
\User\PycharmProjects\2\venv\Scripts\python.exe C:/Users/User/PycharmProjects/2/101_gui/test.py
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/2/101_gui/test.py", line 3, in <module>
response = requests.post('https://api.github.com/user/repos')
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\api.py", line 87, in post
return request('post', url, data=data, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\adapters.py", line 174, in send
timeout=timeout
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 417, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 232, in _get_conn
return conn or self._new_conn()
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 547, in _new_conn
strict=self.strict)
TypeError: __init__() got an unexpected keyword argument 'strict'
Process finished with exit code 1
I am trying to figure out why I cannot at all connect to my bit bucket server, using stashy, using any other lib, even having trouble with calls requests's
Your code works on my machine.
You should try upgrading the requests module by using pip upgrade.
After executing your source code I have no problem executing it accordingly. I think you need to update your request library. Here's how to do that:
https://realpython.com/python-requests/
When I run my Python script to get data from RESTAPI of an application, I get the following error. I installed PIP and I installed requests package for the python. Here is my below query:
./simpleRunQuery.py <args> <args>
Traceback (most recent call last):
File "./simpleRunQuery.py", line 25, in <module>
res = requests.post(url, auth=(args.username, args.password), data=jsonRequest, headers=headers)
File "/Library/Python/2.7/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(54, 'Connection reset by peer'))
I can attach the script, but my script doens't have the lines 112 or 58 or any of these, it's a simple RESTAPI Script that queries and posts results here. Any pointers?
I am trying to send web request to my php code via linux running on raspberry pi. I am using putty to access the OS. When I am running the code, I am getting gai error-2. Below is my code:
import requests
values = {'"firstname":' "abc ", '"lastname":' "xyz"}
r = requests.post('http://rts.msmq.site/security.php', data=values)
I am unable to figure out the problem. Can someone let me know what could be the issue? I am using linux.
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 94, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 407, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
gaierror stands for get_address_info_error, which means urllib is having trouble reaching the hostname 'http://rts.msmq.site/security.php', check that you can nslookup rts.msmq.site or dig rts.msmq.site and ping rts.msmq.site
I can directly download a file that is around 50 megabytes, but when I use python request to do so, it does not work. It returns:
r = sss.get(url, stream=True, headers=my_headers)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests-2.8.1-py2.7.egg/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests-2.8.1-py2.7.egg/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests-2.8.1-py2.7.egg/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests-2.8.1-py2.7.egg/requests/adapters.py", line 426, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))
Here is the url that I've used:
What is the problem?
Try using http:// instead of https:// for your url?
Check out the solution to this question. Might be the solution to the error that you're facing.
Python requests.exception.ConnectionError: connection aborted "BadStatusLine"
Also, it would be helpful to include the url that you're passing into the request in your question.