import requests
content = "-sharpDRETITLE \n-sharpDREFIELD PUBLISHDATE="2018-07-26 08:12:27" "
r = requests.get("http://127.0.0.1:5000/drop_TextRepeat/", data=content)
as shown in the picture, I want to send the string data in content to another computer. (currently using this machine for testing, there is a restful), in cmd that is receiving data, but it always reports an error. The error is as follows. How do you deal with this problem?
r = requests.get("http://127.0.0.1:5000/drop_TextRepeat/", data=content)
Traceback (most recent call last):
File "<ipython-input-90-279b4d1640a1>", line 1, in <module>
r = requests.get("http://127.0.0.1:5000/drop_TextRepeat/", data=content)
File "E:\anoconda\lib\site-packages\requests\api.py", line 70, in get
return request("get", url, params=params, **kwargs)
File "E:\anoconda\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "E:\anoconda\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "E:\anoconda\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "E:\anoconda\lib\site-packages\requests\adapters.py", line 423, in send
timeout=timeout
File "E:\anoconda\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen
chunked=chunked)
File "E:\anoconda\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 361, in _make_request
conn.request(method, url, **httplib_request_kw)
File "E:\anoconda\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "E:\anoconda\lib\http\client.py", line 1284, in _send_request
body = _encode(body, "body")
File "E:\anoconda\lib\http\client.py", line 161, in _encode
(name.title(), data[err.start:err.end], name)) from None
UnicodeEncodeError: "latin-1" codec can"t encode characters in position 10-21: Body ("") is not valid Latin-1. Use body.encode("utf-8") if you want to send it encoded in UTF-8.
the code to receive data is as follows
@app.route("/drop_TextRepeat/", methods=["POST"])
def add_task():
time_start=time.time()
nowTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
pastTime = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
-sharpprint (nowTime)
-sharpurl = request.form.get("siteDomain")
-sharppublishdate = request.form.get("publishdate").strftime("%Y-%m-%d %H:%M:%S")
-sharptext = request.form.get("content")
-sharptitle = request.form.get("title")
-sharpurl = request.json["data"]
-sharpprint (request.form)
-sharpprint (request.data)
data = request.data
data1 = json.dumps(data)
print (data1["data"])
ask the boss to guide one or two