Oct-03-2019, 01:35 PM
When i try to post json data and image in API link i get the error for "Data must not be a string."
ValueError: Data must not be a string.
for line number:39
import pandas import requests import json import codecs import base64 auth_key = ('xxx', 'xxxxxxxxxxxxxxx') URL1 = "https://fls.topdesk.net/tas/api/incidents/" headers = {'Content-type': 'application/json','Content-type':'charset=utf-8'} with open("C:\\Users\\vijsi-in\\PycharmProjects\\RDP Access Automation\\topdesk.png", "rb") as f: encodedZip = base64.b64encode(f.read()) files = encodedZip.decode() print(files) briefDescription = "Test" data = { "briefDescription": briefDescription, "request" : "I am affected by this issue :-" + "\n" + "Yes More detailed information - Kindly I need to activate my office and when I try to activate it I get the attached error PC Number -Desk location", "status": "secondLine", "callerLookup" : {"networkLoginName" : "vijsi-in"}, "category" : { "id" : "7faa6bf8-a30a-422f-a751-5873f23edb0c"}, "subcategory": {"id" : "0ed51db1-5121-4808-830e-5bc14046f4fc"}, "callType": {"id" : "91f897c3-617c-4577-b8ca-2a6b02ff527c"}, "operatorGroup":{"id": "53ba321f-2b61-4c62-93f3-c1cb2c928d36"}, "entryType":{"id": "b330b233-7199-548c-8c47-8586190e3aa3"}, "impact":{"id": "6dd9cf42-0529-52bc-bbee-87872646ac71"}, "urgency":{"id": "7ba734d4-1aa4-4d93-b8de-9796f0845d28"}, "entryType":{"id": "b9743d23-5338-4910-9ac0-87f61a502a90"}, } data_json = json.dumps(data) r = requests.post(URL1,data=data_json,files=files,headers=headers,auth = auth_key) r.status_code a=r.content print(r.status_code) #print(a) c=(a[77:91]) print(c)Result:
ValueError: Data must not be a string.
for line number:39