Ich versuche, eine POST-Anfrage als JSON zu senden.TypeError: b'1 'ist nicht JSON serializable
* E-Mail-Variable vom Typ „Byte“
def request_to_SEND(email, index):
url = "....."
data = {
"body": email.decode('utf-8'),
"query_id": index,
"debug": 1,
"client_id": "1",
"campaign_id": 1,
"meta": {"content_type": "mime"}
}
headers = {'Content-type': 'application/json'}
try:
response = requests.post(url, data=json.dumps(data), headers=headers)
except requests.ConnectionError:
sys.exit()
return response
ich den Fehler:
File "C:\Python34\lib\json\encoder.py", line 173, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'1' is not JSON serializable
Könnten Sie mir bitte sagen, was es ist, dass ich falsch mache?
Können Sie uns etwas, das wir reproduzieren können? Ich habe "Hallo" 'in' email' und '0' in' index' gesetzt, dann kopierte die Definition von 'data', und' json.dumps (data) 'funktionierte gut. –