Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 http post发送错误的数据_Python_Http_Python Requests - Fatal编程技术网

Python http post发送错误的数据

Python http post发送错误的数据,python,http,python-requests,Python,Http,Python Requests,我用tkinter创建了一个简单的输入表单/字段 我想要的是将输入的信息发送到Web服务器 代码如下: import tkinter as tk from tkinter import * import requests API_ENDPOINT = "http://123.123.123.12" def send_req(): r = requests.post(url = API_ENDPOINT, data = data) # extracting response t

我用tkinter创建了一个简单的输入表单/字段 我想要的是将输入的信息发送到Web服务器 代码如下:

import tkinter as tk
from tkinter import *
import requests
API_ENDPOINT = "http://123.123.123.12"

def send_req():
    r = requests.post(url = API_ENDPOINT, data = data) 
    # extracting response text 
    pastebin_url = r.text 
    print("The pastebin URL is:%s"%pastebin_url)

    e1.delete(0, tk.END)
    e2.delete(0, tk.END)
    e3.delete(0, tk.END)
    e4.delete(0, tk.END)
master = tk.Tk()
tk.Label(master, text="first name").grid(row=0)
tk.Label(master, text="last name").grid(row=1)
tk.Label(master, text="Add").grid(row=2)
tk.Label(master, text="Phone").grid(row=3)

e1 = tk.Entry(master)
e2 = tk.Entry(master)
e3 = tk.Entry(master)
e4 = tk.Entry(master)

e1.insert(10, "")
e2.insert(10, "")
e3.insert(10, "")
e4.insert(10, "")

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
data = {'key1': e1, 
                'key2':e2, 
                'key3':e3, 
                'key4':e4}

tk.Button(master, text='send',command=send_req).grid(row=4,column=1, sticky=tk.W, pady=5,)

master.mainloop()

tk.mainloop()
无论我在客户端的字段中输入什么,我总是在服务器端得到这些数据,而不是字段数据:


很明显,代码有问题。 首先,您应该将
数据
作为参数传递给
发送请求

其次,您正在将
key1
分配给
e1
,这是一个
tkinter条目
对象,而不是文本

我相信您想从文本字段发送文本。 因此,您需要这样做:

data = {'key1': e1.get(), 
                'key2':e2.get(), 
                'key3':e3.get(), 
                'key4':e4.get()}

希望这有帮助。

内部
发送请求
。。
r.status\u code
的值是什么?r.status\u code是什么?它是响应的状态码。。。在使用此功能时,只需打印
r.status\u code
yep状态代码为200答案是否解决了问题?如果是,请接受答案或让我们知道问题