I need to call a web requests and Im using Python request module.
I have a requests being served on a machine For ex:55.84.201.228. When I enter it throught the browser it works fine and Im able to view the webpage..
but when I use the requests.get, it does not work..It errors with a socket error..
>>> import requests
>>> r = requests.get('https://55.84.201.228')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='55.84.201.228', port=443): Max retries exceeded with url: / (Caused by <class 'socket.error'>: [Errno 110] Connection timed out)
How can I fix this issue?
>>>r = requests.get('https://www.cnn.com')
This works fine.
I am making a wild guess here since I can't access your machine but from experience, since you are using https on what I assume is some test server try
r = requests.get('https://55.84.201.228', verify=False)
According to the documentation certificate verification is on by default.
Related
ua = UserAgent()
headers={
'user-agent':str(ua.random),
'Connection':'close'
}
r = requests.get(url,headers=headers,timeout=5)
I want to scrape some information from a website ,but the function request.get() raise exception occasionally (sometimes successful but sometime not). I've tried many methods, random u-a, timeout, time.sleep, max tries, but of no use.
Is there something wrong with my code, or is it a fault or some anti-scraper system of the website?
Here is the full exception:
Traceback (most recent call last):
File "d:\AAA临时文档\抢课app\爬虫\run2.py", line 7, in <module>
r=requests.get(url=url,headers=headers,timeout=20)
File "C:\Users\86153\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\86153\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\86153\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\86153\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\86153\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 504, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='www.dy2018.com', port=443): Max retries exceeded with url: /i/103887.html (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x04046A18>, 'Connection to www.dy2018.com timed out. (connect timeout=20)'))
I'm trying to run a python script (that is not mine) which is supposed to connect to an IP address (192.168.1.3) on the LAN.
File "control/insert_to_container.py", line 36, in <module>
res=read_info.open_file()
File "/control/read_info.py", line 21, in open_file
r = requests.get('http://'+line.rstrip('\t')+':491155')
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.3', port=491155): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8fd9e9b250>: Failed to establish a new connection: [Errno 111] Connection refused',))
I specified the IP address in a config file. Would anybody know what the %09 is in the error HTTPConnectionPool(host=192.168.1.3%09. I wondering if this is the source of the error.
Your variable "line" contains a tab, which is then turned into "%09" by the Requests library.
To fix this, you must first ensure that your "line" variable contains no extraneous characters. The most direct way to achieve this is to use .rstrip()
Example:
r = requests.get('http://'+line.rstrip('\t')+':49155')
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 am trying to get a response using python requests. However I'm facing SSL Handshake error. I tried many solutions posted here, but nothing seems to work. Please help. Thanks in advance
This is the code:
import requests
url = "https://androidappsapk.co/download/com.facebook.katana"
requests.get(url, verify = False)
This is the error that I am getting :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 382, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
P.S. - I am using Python 2.7.11
I updated OpenSSL to the latest version and it's working fine now :)
I have a strange problem with a python script.
import requests
argumente = {'NRBUS': 'LINIA_1', 'COORDONATE': '46.195323,21.306300'}
r=requests.get("http://www.roroid.ro/php/GPS_cloud/GPS_cloud.php",params=argumente)
print r.url
print r.text
On my PC is worknig without any problems but on my raspberry PI after some time I end up with
Traceback (most recent call last):
File "testt.py", line 4, in <module>
r=requests.get("http://www.roroid.ro/php/GPS_cloud/GPS_cloud.php",params=argumente)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 375, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.roroid.ro', port=80): Max retries exceeded with url: /php/GPS_cloud/GPS_cloud.php?COORDONATE=46.195323%2C21.306300&NRBUS=LINIA_1 (Caused by <class 'socket.error'>: [Errno 110] Connection timed out)
Thanks for any help.