当前位置: 首页>>代码示例>>Python>>正文


Python Request.encode方法代码示例

本文整理汇总了Python中urllib.request.Request.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Request.encode方法的具体用法?Python Request.encode怎么用?Python Request.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request.Request的用法示例。


在下文中一共展示了Request.encode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import encode [as 别名]
 def download(self, request):
     """ """
     mimetype = 'application/x-ofx'
     HTTPheaders = {'Content-type': mimetype, 'Accept': '*/*, %s' % mimetype}
     # py3k - ElementTree.tostring() returns bytes not str
     request = self.ofxheader + ET.tostring(request).decode()
     # py3k: urllib.request wants bytes not str
     request = Request(self.url, request.encode(), HTTPheaders)
     try:
         with contextlib.closing(urlopen(request)) as response:
             # py3k: urlopen returns bytes not str
             response_ = response.read().decode()
             # urllib2.urlopen returns an addinfourl instance, which supports
             # a limited subset of file methods.  Copy response to a StringIO
             # so that we can use tell() and seek().
             source = StringIO()
             source.write(response_)
             # After writing, rewind to the beginning.
             source.seek(0)
             self.response = source
             return source
     except HTTPError as err:
         # FIXME
         print(err.info())
         raise
开发者ID:P-Laf,项目名称:ofxtools,代码行数:27,代码来源:Client.py

示例2: download

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import encode [as 别名]
 def download(self, request):
     """ """
     mimetype = 'application/x-ofx'
     HTTPheaders = {'Content-type': mimetype, 'Accept': '*/*, %s' % mimetype, "User-Agent": "httpclient"}
     # py3k: ElementTree.tostring() returns bytes not str
     request = self.ofxheader + ET.tostring(request).decode()
     # py3k: urllib.request wants bytes not str
     request = Request(self.url, request.encode(), HTTPheaders)
     with contextlib.closing(urlopen(request)) as response:
         # py3k: urlopen returns bytes not str
         response_ = response.read()
         # urllib2.urlopen returns an addinfourl instance, which supports
         # a limited subset of file methods.  Copy response to a StringIO
         # so that we can use tell() and seek().
         source = StringIO()
         if isinstance(response_, str):
             source.write(response_)
         else:
             response_ = response_.decode('utf-8')
             source.write(response_)
         # After writing, rewind to the beginning.
         source.seek(0)
         self.response = source
         return source
开发者ID:PierreRochard,项目名称:ofxtools,代码行数:26,代码来源:Client.py


注:本文中的urllib.request.Request.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。