0

我正在尝试摆脱在 python27 API 中使用 httplib 时遇到的异常 HTTPException('ApplicationError: 5 ',)(在 google appengine 上运行)-在与来自 AppEngine 的外部 api 进行通信时在这篇文章 ApplicationError2 和 ApplicationError5中进一步详细说明. 我想我也许可以尝试使用 httplib2。我可以看到调用 httplib 的 API 的唯一部分是:

def _get_conn(self):
    return httplib.HTTPConnection(str(self.host), str(self.port), timeout=120)

httplib2 中是否有直接等效于httplib.HTTPConnection()的方法?我进行了搜索,但找不到任何东西。

4

1 回答 1

1

似乎有,见AppEngineHttpConnectionhttp2源代码

但是,AFAIK 这些不是官方 httplib2 API 的一部分,如其文档中所示,您宁愿执行以下操作:

import httplib2
h = httplib2.Http()
resp, content = h.request("http://bitworking.org/")
assert resp.status == 200
assert resp['content-type'] == 'text/html'

您是否考虑过使用Request library,它最近受到了很多好评。

于 2012-02-13T11:19:39.477 回答