简体   繁体   中英

Python REST API Issues

I am working on a tool that queries a number of APIs, one of which is a RESTful API. All of the other functions (API calls) of my program work fine with requests.get(), however with the REST API, I do not seem to be able to access the actual content of the response, only the status code. ie when I simply print the response, (not response.status_code) I get: <Response [200]> output to the screen. Any ideas?

Snippet of code:

# The URL is correct in my program, For sure.
url = ('http://APIurl/%s' % entry)
    try:
       response = requests.get(url)

       # prints <Response [200]>
       print response

       # Fails, expecting JSON that isn't there
        results.append(response.json())

打印响应对象的属性以查看其可用属性:

print response.__dict__

如果内容无效json,则response.text是您的朋友。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM