1

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

1
  • FYI: not an answer to your question but, I use the excellent Requests package (python-requests.org) for all HTTP client requirements I have. Commented Oct 10, 2012 at 0:33

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

5 Comments

Then how will I be able to POST to the hostname? As I mentioned in a comment below: I am supposed to get either an "OK" or "Err" back depending on the given parameters.
It looks like you are literally using those host names? If so, www.bar.com does exist. foo.bar.com is not a registered domain. It can not be resolved to an IP address and therefore can not be contacted.
Nono, I am not using those host names! :)
What is the second hostname? Are you certain that it is valid? If you have the host's IP address, try that instead.
SOLVED! The problem was the "www." before foo.bar.com. A typo by me. Thank you kindly for the answers!
0

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")

3 Comments

I don't have any "HTTP://" in my url. I tried to ping www.bar.com, works fine. But I can't ping www.foo.bar.com. How shall I reach www.foo.bar.com/submit.jsp if I can't connect to www.foo.bar.com ?
Are you trying to post to a website that isn't your website?
Yes. It is schoolwork. The server is to respons with "OK" if my parameters are accurate, and "Err" if not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.