Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to respond to content with python requests

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people don't understand the knowledge points of this article "how to respond to content with python requests", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "how to respond to content with python requests".

1. Binary response content, accessing the request response body in bytes.

For non-text requests:

>>> r.contentb'[{"repository":{"open_issues":0,"url":"https://github.com/...

JSON response content, Requests has a built-in JSON decoder to process JSON data.

>>> import requests>>> r = requests.get('https://github.com/timeline.json')>>> r.json()[{u'repository': {u'open_issues': 0, u'url': 'https://github.com/...

3. Original response content, you can access r.raw.

If you do want to do this, make sure you set stream=True in your initial request. You can do this:

>>> r = requests.get ('https://github.com/timeline.json', stream=True)>> r.raw>> r.raw.read (10)'\x1f\x8b\x08\x00\x03' The above is about the content of this article on "How to use python requests to respond to content". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report