Stack Overflow Asked by Senan Zedan on January 12, 2021
I have the class:
class ApplicationServer(BaseHTTPRequestHandler):
def do_POST(self):
try:
content_type, post_dict = parse_header(self.headers['content-type'])
if content_type == 'multipart/form-data':
post_data = parse_multipart(self.rfile, post_dict)
elif content_type == 'application/json':
length = int(self.headers['content-length'])
post_data = parse_qs(self.rfile.read(length), keep_blank_values=1)
else:
post_data = {}
new_data = {key.decode(): val[0].decode() for key, val in post_data.items()}
......
I’m sending through HTTP request class instance, But in the do_POST method it’s receiving as bytes and doing decode() convert it to string, my question is there any way to convert back to class instance?
The way that doing request:
if __name__ == '__main__':
for i in range(11):
order = Order(100, "Buy")
status = requests.post("http://localhost:8000", data={"order": order}, headers={'Content-Type': 'application/json'})
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP