【问题标题】:Is there a direct equivalent to httplib.HTTPConnection() in httplib2httplib2 中是否有直接等效于 httplib.HTTPConnection()
【发布时间】:2012-02-10 12:55:22
【问题描述】:

我正在尝试摆脱在 python27 API 中使用 httplib 时遇到的异常 HTTPException('ApplicationError: 5 ',)(在 google appengine 上运行) - 在这篇文章 ApplicationError2 and ApplicationError5 when communicating with external api from AppEngine 中有更详细的说明。我想我或许可以尝试使用 httplib2。我可以看到调用 httplib 的 API 的唯一部分是:

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

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

【问题讨论】:

    标签: python google-app-engine python-2.7 httplib httplib2


    【解决方案1】:

    好像有,见http2 source code中的AppEngineHttpConnection

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      相关资源
      最近更新 更多