gpt4 book ai didi

python urllib2 urlopen 响应

转载 作者:IT老高 更新时间:2023-10-28 20:46:00 30 4
gpt4 key购买 nike

python urllib2 urlopen 响应:

<addinfourl at 1081306700 whose fp = <socket._fileobject object at 0x4073192c>>

预期:

{"token":"mYWmzpunvasAT795niiR"}

最佳答案

您需要将生成的类文件对象绑定(bind)到一个变量,否则解释器只是通过 repr 转储它:

>>> import urllib2
>>> urllib2.urlopen('http://www.google.com')
<addinfourl at 18362520 whose fp = <socket._fileobject object at 0x106b250>>
>>>
>>> f = urllib2.urlopen('http://www.google.com')
>>> f
<addinfourl at 18635448 whose fp = <socket._fileobject object at 0x106b950>>

要获取实际数据,您需要执行 read()

>>> data = f.read()
>>> data[:50]
'<!doctype html><html itemscope="itemscope" itemtyp'

查看返回的标题:

>>> print f.headers
Date: Thu, 23 Aug 2012 00:46:22 GMT
Expires: -1
Cache-Control: private, max-age=0
... etc ...

关于python urllib2 urlopen 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12083231/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com