http.client

How to upload a binary/video file using Python http.client PUT method?

删除回忆录丶 提交于 2020-06-28 05:56:12
问题 I am communicating with an API using HTTP.client in Python 3.6.2. In order to upload a file it requires a three stage process. I have managed to talk successfully using POST methods and the server returns data as I expect. However, the stage that requires the actual file to be uploaded is a PUT method - and I cannot figure out how to syntax the code to include a pointer to the actual file on my storage - the file is an mp4 video file. Here is a snippet of the code with my noob annotations :)

Example of including a certficate in a post request with python and http.client

大兔子大兔子 提交于 2019-12-12 17:16:15
问题 I am trying to POST xml to a site using python. I have to include a certificate but am unsure of how to do this. Is it enough to specify the file path of the certificate locally on my computer? Can anybody show my an example of how to include the certificate in the request? import http.client, urllib.parse xml="""<?xml version="1.0" encoding="UTF-8"?> <home> <bathroom>1</bathroom> <kitchen>1</kitchen> <street>515</street> </home>);""" headers = {"username": "password"} conn = http.client

http.client.RemoteDisconnected: Remote end closed connection without response

Deadly 提交于 2019-12-11 04:36:58
问题 I am using the http.client module to download files from an apache server. Basically each thread is downloading files from the server. But when there are a large number of threads running I seem to be facing a problem where some threads get terminated. This is the main part of my code : def down(i,t_end,con,s_ip): num = 0 while time.time()<t_end: con[i].request("GET","/"+file_name) r1 = con[i].getresponse() data1 = r1.read() handle = open('/home/client1/test/try'+str(num)+str(i)+'.txt','wb')