0

I am trying to upload a file to the server in a simple way and I am getting the following error:

HTTP/1.1 411 Length Required

Content-Type: text/html

Date: Wed, 01 Jul 2015 03:05:33 GMT

Connection: close

Content-Length: 24

Length Required

I tried to insert length in different parts and looks like is not working, any suggestions?

import socket
import httplib
import os.path

target_host = "192.168.1.1"
target_port = 80
total_size = os.path.getsize('/root/test.html')

client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

client.connect((target_host,target_port))

client.send("PUT /root/test.html HTTP/1.1\r\nHost:192.168.1.1\r\n\r\n" )

response = client.recv(4096)

print response
Cœur
  • 37,241
  • 25
  • 195
  • 267
Peterpan
  • 1
  • 1

2 Answers2

0

Have you tried implementing this with requests?

You could easily specify the missing content-length header that is causing your error.

atlspin
  • 76
  • 8
0

Check out this answer: Is there any way to do HTTP PUT in python

Here's an example using the requests library:

payload = {'username': 'me', 'email': 'me@me.com'}
>>> r = requests.put("http://somedomain.org/endpoint", data=payload)
Community
  • 1
  • 1
Dportology
  • 836
  • 1
  • 9
  • 32