I have this code in python to make requests:
import requests
import json
import csv
import pandas as pd
with open('C:/asg/ftpfiles/data.json') as json_file:
dataparse = json.load(json_file)
iPartNumber = dataparse['distributornumsku']
r = requests.get('https://online.xxx.com/xxx/items/' + str(iPartNumber), auth=('test@test.com', 'test')).json()
with open('itemdatasku.json', 'w') as json_file:
json.dump(r, json_file)
The data JSON I’m reading is:
{"distributornumsku": "RFBB5-56C40K2/32"}
However the script crashes with the error:
Traceback (most recent call last):
File "C:\asg\ftpfiles\api.py", line 28, in <module>
r = requests.get('https://online.xxx.com/xxx/items/' + str(iPartNumber), auth=('test@test.com', 'test')).json()
File "C:\Users\serverqnapwin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The error was because I’m sending the value RFBB5-56C40K2/32 and there is the problem maybe the “/“ or who knows is causing the problem/ If I use any other value offered than RFBB5-56C40K2/32 it works.
The problem is the code is sending incorrectly the request at difference of other cases for example. The script is sending:
https://online.xxx.com/xxx/items/RFBB5-56C40K2/32
As you see the last “/32” is the problem is not sending as a whole “RFBB5-56C40K2/32”. How can I avoid the /32 that it splits after the “/“ as if was another subdirectory after the “/“?
What could be the problem and how can I fix the script to avoid this error?