开发者

Issue with python httplib2 on linux

开发者 https://www.devze.com 2023-03-18 19:09 出处:网络
I\'m using the following snippet of code to call a web service, that requires basic auth: import urllib

I'm using the following snippet of code to call a web service, that requires basic auth:

import urllib
import httplib2
url='http://heywatch.com/download.json'
body={'username':'my_username','password':'my_password'}
header_data={'Accept': 'application/json'}
http=httplib2.Http()
response, content = http.request(url, 'POST', headers=header_data,     body=urllib.urlencode(body))

I'm running this same snippet on two different environments:

Mac OSX 10.6.6, python version 2.6.1 - I get the correct response

Linux - centos, python version 2.6.6 - I get the following exception:

.....
File "/usr/lib/python2.6/site-packages/httplib2/__init__.py", line 1129, in _conn_request
    raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
ServerNotFoundError: Unable to find the server at heywatch.com

I've run this code on multiple linux flavors with different python versions and everything works fine. I also noticed curl does not work properly on the particular machine. The following curl command (which mimics the code above) works fine on my Mac OSX:

curl -u username:password -X POST -d "url=https://s3.amazonaws.com/my_video_to_be_encoded.mov" -d "title=new_video" -d "automatic_encode=true" -d "ping_url_after_encode=http://mydomain/video_encode_success" https://heywatch.com/download.json

but fails on the affected linux workstation with the following message:

curl: (6) Couldn't resolve h开发者_Python百科ost 'heywatch.com'

Any idea why this is happening? It seems like some OS setting is incorrect. If it helps, I'm using an amazon version of linux in amazon ec2, which is fairly locked down.


This has to do with how the linux box is resolving heywatch.com. CAn you do a ping to see if heywatch.com is reachable (probably not). You might want to look at /etc/resolv.conf on your linux box to see what nameservers are configured and ask amazon if you are using any of theirs.

FWIW, I just tried to resolve heywatch on my ubuntu in linode and it seems to resolve fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号