I am trying to post two parameters using HTTP POST-request to http://foo.bar.com/submit.jsp .
This works.
conn = httplib.HTTPConnection("www.bar.com")
conn.request("POST", "",parameters)
But this does not, could someone explain to me why it does not and how the correct way is?
conn = httplib.HTTPConnection("www.foo.bar.com")
conn.request("POST", "/submit.jsp", parameters)
I am getting this error
File "example.py", line 68, in <module>
conn.request("POST", "/submit.jsp", parameters)
File "/usr/lib/python2.7/httplib.py", line 958, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 992, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 757, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
Thanks in advance
Whatever hostname you are really using in place of www.foo.bar.com
can not be resolved to an IP address. Note that your first example used www.bar.com
, not www.foo.bar.com
. While these are only examples, the second hostname that you are using is bad.
The path /submit.jsp
is not the problem here, if that is what you are actually trying to test?
This error means that python cannot reach the HTTP server you defined in the function, You could have a unneeded "HTTP://", A typo'd url, if you're using IPV6 it could be the form of your address or other network issues.
This might help;
Error while using conn = httplib.HTTPConnection ("http://ipaddr:port")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.