Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Json请求编码_Python_Json_Python 3.x - Fatal编程技术网

Python Json请求编码

Python Json请求编码,python,json,python-3.x,Python,Json,Python 3.x,尝试进行json调用,但得到了这个结果,我认为问题在于编码,因为我可以保证url和键都是正确的 有人知道怎么解决这个问题吗 这是我的代码: ocppurl = "http://xxxxxxxxxx.com/xxxxxxxx/rest/xxxxxxxx/" headers = {'Content-Type': 'application/json', 'xxxxxxx': 'xxxxx-00001'} timeoutvar = 55 tiporeq = "GetConf

尝试进行json调用,但得到了这个结果,我认为问题在于编码,因为我可以保证url和键都是正确的

有人知道怎么解决这个问题吗

这是我的代码:

ocppurl = "http://xxxxxxxxxx.com/xxxxxxxx/rest/xxxxxxxx/"
headers = {'Content-Type': 'application/json', 'xxxxxxx': 'xxxxx-00001'}
timeoutvar = 55
tiporeq = "GetConfiguration"
payload = json.dumps({"key": "xxxxxxx","value": "90"})
reqnow = str(ocppurl + tiporeq) + ",\n\n" + str(headers) + ",\n\n" + str(payload) + ",\n\n" + "Timeout:" + str(timeoutvar)
reqinp.delete('1.0', END)
reqinp.insert(tk.INSERT, reqnow)

def runpost():
    getconfval=reqinp.get(1.0, "end-1c")
    getconfvalF=getconfval.replace('\n\n', '').strip()
    repinp.delete('1.0', END)
    repinp.insert(tk.INSERT, "Request:\n\n"+getconfvalF)
    r = requests.request("POST",getconfvalF)
    statReason = ("\n\nStatus:\n\n"+str(r.status_code) + " - " + str(r.reason) + "\n\nResponse:\n\n" + str(r.text))
    #repinp.delete('1.0', END)
    repinp.insert(tk.INSERT, statReason)
    lblexpect.config(text="Expected Response:\n\n" + str(expResp))
编辑:

例如:

import requests
import json

url = "http://xxxxxxx/rest/xxxxx/"
tiporeq = url + "GetConfiguration"
payloads = json.dumps({})
headers = {'Content-Type': 'application/json','stat': '1234'}
timeoutvar=10

reqped = str(tiporeq) + ",\n\nheaders=" + str(headers) + ",\n\ndata=" + str(payloads) + ",\n\n" + "timeout=" + str(
  timeoutvar)

reqped = reqped.replace('\n\n', '').strip()
reqped = reqped.replace(' ', '').strip()

response = requests.request("POST", reqped)

print(response.text)
此给定错误(我需要此错误才能正常工作)

这很有效

  reqjson = requests.request("POST", url, headers=headers, data=payload, timeout=5)

是什么让您怀疑问题在于编码?你认为问题出在什么编码上?还有什么是
rekinp
tk
?还有什么是
repinp
?您能提供指定的值吗?@all。reqinp是一个文本框,其中显示请求并可以进行更改。repinp是显示请求和响应的文本框。我认为问题在于编码,因为响应:%7D,%7B%22键%22:%20%xxxxxxxxx%22,%20%22值%22:%20%22-1%22%7D
#setting the request
pedido = str(tiporeq) + ",\n\nheaders=" + str(headers) + ",\n\ndata=" + str(payload) + ",\n\n" + "timeout=" + str(timeoutvar)
reqinp.insert(tk.INSERT, pedido)
#getting the request
getconfval=reqinp.get(1.0, "end-1c")
getconfvalF=getconfval.replace('\n\n', '').strip()
getconfvalF = getconfvalF.replace(' ', '').strip()
reqjson = requests.request("POST", getconfvalF)
  reqjson = requests.request("POST", url, headers=headers, data=payload, timeout=5)