Python请求:在哪里可以找到所有可能的属性?

Python请求:在哪里可以找到所有可能的属性?,python,attributes,python-requests,Python,Attributes,Python Requests,我与lambda函数一起使用(如果您称它为其他函数,请更正我)来获取url。考虑到url根据epoch()的值而变化,我想打印它以进行调试 幸运的是,print(kiwi.url)是有效的,因为kiwi.url是存在的,但是作为将来的参考,我如何在不依赖运气的情况下找到python请求甚至其他模块的所有可能属性呢 import time, requests epoch = lambda: int(time.time()*1000) kiwi = s.get('http://www.example

我与lambda函数一起使用(如果您称它为其他函数,请更正我)来获取url。考虑到url根据
epoch()
的值而变化,我想打印它以进行调试

幸运的是,
print(kiwi.url)
是有效的,因为
kiwi.url
是存在的,但是作为将来的参考,我如何在不依赖运气的情况下找到python请求甚至其他模块的所有可能属性呢

import time, requests
epoch = lambda: int(time.time()*1000)
kiwi = s.get('http://www.example.com/api?do=%i' % epoch())
print(kiwi.url) #I found the .url attribute by chance.
           ^
在shell中使用
dir()

>>> import requests
>>> req = requests.get('http://www.google.com')
>>> dir(req)
['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__',
'__format__', '__getattribute__', '__getstate__', '__hash__', '__init__',
'__iter__', '__module__', '__new__', '__nonzero__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed',
'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 
'encoding', 'headers', 'history', 'is_redirect', 'iter_content', 'iter_lines',
'json', 'links', 'ok', 'raise_for_status', 'raw', 'reason', 'request',
'status_code', 'text', 'url']

一般来说,您可以使用和函数内省Python对象:

>>> import requests
>>> response = requests.get('http://httpbin.org/get?foo=bar')
>>> dir(response)
['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url']
>>> 'url' in dir(response)
True
>>> vars(response).keys()
['cookies', '_content', 'headers', 'url', 'status_code', '_content_consumed', 'encoding', 'request', 'connection', 'elapsed', 'raw', 'reason', 'history']
您也可以只使用,Python将格式化类上的docstring
response.url
没有文档字符串,但列在属性部分

对于
请求
具体来说,只需查看优秀的。
url
属性列为的一部分。

您尝试过吗?另请参阅