Error while sending http post request to http server

Topics about the Software of Revolution Pi
Post Reply
Pradip
Posts: 10
Joined: 09 Jul 2020, 09:15
Answers: 0

Error while sending http post request to http server

Post by Pradip »

Hello Developers,
anyone can help me on below error while sending http post request to http server

I am unable to send http post request to http server using revpi connect
My Code is

Code: Select all

 import requests
pload = {'username':'Olivia','password':'123'}
r = requests.post('https://httpbin.org/post',data = pload)
print(r.text) 
I'm getting following error:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 138, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 75, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 594, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 350, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 837, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 281, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 147, in _new_conn
self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x75cc91d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 643, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 363, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /post (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x75cc91d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 3, in <module>
r = requests.post('https://httpbin.org/post',data = pload)
File "/usr/lib/python3/dist-packages/requests/api.py", line 110, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /post (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x75cc91d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))


But on other hand same code works perfectly. When I run the above code on raspberry pi we get response from http server successfully.

{
"args": {},
"data": "",
"files": {},
"form": {
"password": "123",
"username": "Olivia"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "28",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.12.4",
"X-Amzn-Trace-Id": "Root=1-60efd7c2-0c1f33810a5788ed4f932c41"
},
"json": null,
"origin": "110.227.1.43",
"url": "https://httpbin.org/post"
}
User avatar
Steven
Posts: 24
Joined: 29 Mar 2019, 12:01
Answers: 0

Re: Error while sending http post request to http server

Post by Steven »

Hello,

for me it seems you have some messy network configuration.
If you have two network cables connected be sure you have proper metrics set up for eth0 and eth1.
I think the network traffic is not routed into the right network interface.

Try to ping that server from shell.

Code: Select all

ping httpbin.org
or in the case ICMP is blocked:

Code: Select all

nslookup httpbin.org
result should look like:
Non-authoritative answer:
Name: httpbin.org
Address: 52.201.75.114
Name: httpbin.org
Address: 18.235.124.214
Post Reply