Home > Software design >  Get the specific response parameter with urllib in python
Get the specific response parameter with urllib in python

Time:01-12

I am able to perform a web request and get back the response, using urllib.

from urllib import request
from urllib.parse import urlencode
response = request.urlopen(req, data=login_data)
content = response.read()

I get back something like b'{"token":"abcabcabc","error":null}'

How will i be able to parse the token information?

CodePudding user response:

You can use the json module to load the binary string data and then access the token property:

token = json.loads(bin_data)['token']
  •  Tags:  
  • Related