简体   繁体   English

linux 上的 python httplib2 问题

[英]Issue with python httplib2 on linux

I'm using the following snippet of code to call a web service, that requires basic auth:我正在使用以下代码片段来调用需要基本身份验证的 web 服务:

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 Mac OSX 10.6.6,python 版本 2.6.1 - 我得到正确的响应

Linux - centos, python version 2.6.6 - I get the following exception: Linux - centos,python 版本 2.6.6 - 我得到以下异常:

.....
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.我已经在具有不同 python 版本的多种 linux 风格上运行了此代码,并且一切正常。 I also noticed curl does not work properly on the particular machine.我还注意到 curl 在特定机器上无法正常工作。 The following curl command (which mimics the code above) works fine on my Mac OSX:以下 curl 命令(模仿上面的代码)在我的 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:但在受影响的 linux 工作站上失败,并显示以下消息:

curl: (6) Couldn't resolve host '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.如果有帮助,我在亚马逊 ec2 中使用linux 的亚马逊版本,该版本已被完全锁定。

This has to do with how the linux box is resolving heywatch.com.这与 linux 盒子如何解析 heywatch.com 有关。 CAn you do a ping to see if heywatch.com is reachable (probably not).您可以 ping 以查看 heywatch.com 是否可以访问(可能不是)。 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.您可能想查看 linux 框上的 /etc/resolv.conf 以查看配置了哪些名称服务器,并询问亚马逊您是否正在使用它们中的任何一个。

FWIW, I just tried to resolve heywatch on my ubuntu in linode and it seems to resolve fine. FWIW,我只是尝试在 linode 中的 ubuntu 上解决 heywatch,它似乎解决得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM