Python httplib Name or service unknown

I am trying to use httplib to send authorize.net credit card information. When I try to send a request, I get the following trace:

File "./lib/cgi_app.py", line 139, in run res = method() File "/var/www/html/index.py", line 113, in ProcessRegistration conn.request("POST", "/gateway/transact.dll", mystring, headers) File "/usr/local/lib/python2.7/httplib.py", line 946, in request self._send_request(method, url, body, headers) File "/usr/local/lib/python2.7/httplib.py", line 987, in _send_request self.endheaders(body) File "/usr/local/lib/python2.7/httplib.py", line 940, in endheaders self._send_output(message_body) File "/usr/local/lib/python2.7/httplib.py", line 803, in _send_output self.send(msg) File "/usr/local/lib/python2.7/httplib.py", line 755, in send self.connect() File "/usr/local/lib/python2.7/httplib.py", line 1152, in connect self.timeout, self.source_address) File "/usr/local/lib/python2.7/socket.py", line 567, in create_connection raise error, msg gaierror: [Errno -2] Name or service not known 

I create my request like this:

 mystring = urllib.urlencode(cardHash) headers = {"Content-Type": "text/xml", "Content-Length": str(len(mystring))} conn = httplib.HTTPSConnection("secure.authorize.net:443", source_address=("myurl.com", 443)) conn.request("POST", "/gateway/transact.dll", mystring, headers) 

to add another layer to it, it worked on our development server with httplib 2.6 and without the source_address parameter in httplib.HTTPSConnection.

Any help is greatly appreciated.

==================================================== ==========

EDIT:

I can run it from the command line. Apparently this is some kind of permission issue. Any ideas what permissions I need to grant so that users can do this? Perhaps Apache cannot open the port?

+6
python ssl
source share
4 answers

The problem ultimately came down to selinux stopping apache from receiving this port. Disabling selinux fixed the problems. I had a problem later when I did not have /var/www/.python-eggs/, so MySQLdb was importing. But after mkdir this has been fixed.

+2
source

As a (obvious) heads-up, this same error can also be caused by including the protocol in the host parameter. For example, this code:

 conn = httplib.HTTPConnection("http://secure.authorize.net", 80, ....) 

will also result in the error "gaierror: [Errno -2] Name or service not known", even if all the settings on your network are correct.

+12
source

gaierror: [Errno -2] Name or service unknown

This error often indicates a failure of your DNS resolver. Does ping secure.authorize.net successful responses from the same server that gaierror receives? Does this name have a typo?

+6
source

transfer port separately from host:

 conn = httplib.HTTPSConnection("secure.authorize.net", 443, ....) 
0
source

All Articles