How do I parse a JSON response from Python Requests?

后端 未结 7 1225
悲&欢浪女
悲&欢浪女 2021-02-19 00:09

I am trying to parse a response.text that I get when I make a request using the Python Requests library. For example:

def check_user(s         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 00:34

        import json
    
        def check_user(self):
            method = 'POST'
            url = 'http://localhost:5000/login'
            ck = cookielib.CookieJar()
            response = requests.request(method,url,data='username=test1&passwd=pass1', cookies=ck)
    
            #this line converts the response to a python dict which can then be parsed easily
            response_native = json.loads(response.text)
    
            return self.response_native.get('result') == 'success'
    

提交回复
热议问题