Reputation: 529
So I try to upload a file on a Remote Device.
If I use the Code:
#!/usr/bin/python
import httplib
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import poster
register_openers()
params = {'restore': open("Config.cfg", "rb"), 'upload': 'PC ==>; Unit'}
datagen, headers = multipart_encode(params)
request = urllib2.Request('http://www.test.com/saveRestore.htm.cgi', datagen, headers)
u = urllib2.urlopen(request)
print u.read()
The file is Uploaded with the Content-Type text/plain ..
So how do I Change this content-type for example to text/html ?
Upvotes: 1
Views: 8117
Reputation: 731
You can use mechanize lib from python:
import mechanize
b = mechanize.Browser()
# Set any header you like:
b.addheaders = [('Content-Typoe', 'text/html; charset=utf-8')]
response = b.open('http://www.reddit.com')
data = response.read()
Upvotes: 1
Reputation: 4150
Add:
headers['Content-Type'] = 'text/html'
Before instantiating your Request object.
Upvotes: 4