“invalid character 'u' looking for beginning of value”Parsing Error from an Service developed in golang

孤街醉人 提交于 2020-12-13 03:56:27

问题


I am trying to have the response from API which is developed in Golang. Using PostMan I get the proper response, but when I use requests library, I get the following message:

{  
    u'status':400,
    u'title':u'Unable to parse data',
    u'code':u'400001',
    u'id':u'edf83LlwYx',
    u'detail':u"invalid character 'u' looking for beginning of value"
}

My Python script is:

import requests
import json
import data

url = data.user_login

headers = {
    'Content-Type': 'application/json',
    'content-encoding': 'deflate'
}

form = {
    "username": "askjhashdasjd",
    "password": "asdfASDF1234#="
}

response = requests.post(url,headers=headers, data=form)
json_data = json.loads(response.text)
print json_data

I am getting the proper response from the other services using this script.


回答1:


data_to_send = json.dumps(form).encode("utf-8")
response = requests.post(url, data=data_to_send)

This Makes the thing done :)



来源:https://stackoverflow.com/questions/49082081/invalid-character-u-looking-for-beginning-of-valueparsing-error-from-an-serv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!