Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to respond to content with python requests

Shulou Source: shulou.com Published: 2022-05-31 10:40:56 09月16日 Update

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.

Tags: Content articles knowledge articles original binary value most bytes that is data text methods more steps knowledge points industry decoders information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Linux OPPO Reno Docker