Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post JSON dat and Image
#3
When i try to post json data and image in API link i get the error for "Data must not be a string."

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
Reply


Messages In This Thread
Post JSON dat and Image - by vijsi - Sep-25-2019, 06:58 AM
RE: Post JSON dat and Image - by buran - Sep-25-2019, 07:29 AM
RE: Post JSON dat and Image - by vijsi - Oct-03-2019, 01:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add an image to an existing facebook post using python graph API? Ascalon 0 2,911 Dec-01-2020, 08:33 PM
Last Post: Ascalon
  Post JSON from python to PHP don't give expected result pgagnebin 1 4,699 Sep-04-2019, 10:29 PM
Last Post: micseydel
  Help with passing command line input to HTTP POST json sf05wrx 2 3,188 Feb-25-2019, 11:19 PM
Last Post: sf05wrx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020