Python POST error 500, only with Windows 7 and file bigger than 1Mb

I'm using Python 2.7 to Post some data to a server: while this works in Linux and OS X, in Windows it keep uploading for over 4 minutes and then give up with a "Error 500". But ONLY if file > 1Mb. On server side the error is generated due to a corrupted file transmission. I've tried also Python 2.5, to run it in either a Virtual Machine and in two different native Windows environments. Windows version is Win7 x64.

  1. Works with files <1Mb
  2. Works with any file size under OS X and Linux (Ubuntu)
  3. If I upload the same file through web interface, or linux or os/x it works perfectly, so the problem seems not to be the file itself.

CODE:

data = {
    'title': title,
    'file': open(filename),
    'filename': filename
}

datamulti, headers = multipart_encode(data)
request = urllib2.Request(url, datamulti, headers)
print(result.read())

Answers


Try this instead:

data = {
    'title': title,
    'file': open(filename, 'rb'),
    'filename': filename
}

This will make it so the file is opened in binary mode instead of text mode.


Here's a working version, tested in win32:

    data = {
    'title': title,
    'file': open(filename, 'rb'),
    'filename': filename
    }

    datamulti, headers = multipart_encode(data)
    request = urllib2.Request(url, datamulti, headers, None, True)
    print urllib2.urlopen(request).read()

Need Your Help

Local Time To UTC time pytz

python datetime python-2.7 pytz

I converted python datetime with help of pytz.

FPGA input into Simulink

usb simulink fpga

I have a DE2i-150 board. I currently have a Simulink model that introduces a sinusoidal input into an external control system. Rather than using the Simulink library for my input how would I use the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.