3

When I run the same python code:

url = 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
file_to_send = {'filename': (filename, open(filename, 'rb'))}
r = requests.post(url, files=file_to_send)
print(r.text)

I get different results dependent on OS. In macOS and Linux, the r.text is:

<html><head><title>MinXSS HAM Radio Beacon Upload</title></head><body>
<form method='post' action='fileupload.php' enctype='multipart/form-data'[>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload' />
</form><br/>Uploaded file '2018-10-13T14_35_30.371095_SFJPM86_40.241_-105.2353.dat'<br/></body></html>

but on Windows it's:

<html><head><title>MinXSS HAM Radio Beacon Upload</title></head><body>\n
<form method='post' action='fileupload.php' enctype='multipart/form-data'[>\n
Select File: <input type='file' name='filename' size='10' />\n
<input type='submit' value='Upload' />
</form></body></html>

Here is an example file to upload.

When I check the server, the files do actually successfully upload for macOS and Linux but not for Windows. When I go to the fileupload.php script on the server in any browser in macOS or Windows, I can upload the files that were generated on any OS successfully. It seems there must be something different in requests on Windows.

Following @james's suggestion, I've used the request.Request().prepare() to see what's being sent. Here are the results from macOS (which works with the server):

In [4]: prep.method
Out[4]:  'POST'
In [5]: prep.url
Out[5]: 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
In [6]: prep.headers
Out[6]: {'Content-Type': 'multipart/form-data; boundary=710071eb200fc5f402d3a45b71e8289b', 'Content-Length': '2090'}
In [8]: prep.body
Out[8]: b'--710071eb200fc5f402d3a45b71e8289b\r\nContent-Disposition: form-data; name="filename"; filename="/Users/jmason86/MinXSS_Beacon_Decoder/output/2018-10-18T22_18_37.345945_SFJPM86_40.240_-105.2353.dat"\r\n\r\n\xc0\x00\x9a\x92\x00\xb0\xa6d`\x86\xa2@@@@\xe1\x03\xf0\x08\x19\xc1o\x00\xf7\xf14\xd6EG\x02\n\x86K\x00\x0c\x00\x01\x00.t\x01\x030\x03\x00\x03y\x00\x00\x01\xfa\xc7\x10\x01\x03\x00\x00\x01Z\x80\x04\x01\x00\x00\x00\x92\x00\x00\x00!\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00_\x00G\x13\x00\x00\n\x80\xf6\x01\xe2\x03\xd3\x0b\x06\x08\x90\x18\x05\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x8e\x01\x13\x00m\x00\x00d\x88\x01\x00\x00\xac%\x01\x00\x07\x0b \x17@\x15\x90\x15\x80\x17@\x18\xe0\xceXa\x08\x00x\x07\x08\x00\x80\x06\x08\x000\x06\x18\x00P 0\x01\x90\r\x18\x00x\x13M\x05D\x05Q\x05\t\x08\x14\x00\x9e\x05l\x00\xa0\x05\xf3\x01\\\x00O\x02R\x02S\x01S\x013\x01\x00\x00\x08\x01\x00\x00~\x00\x00\x00\xcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/ \x12\xd8\x00\x00\x00\x05\x07\x02\x00\x00\x00\'\x06\x00\x00\t\x06\x00\x00\x00\x00\x00\x00\xfc\xff\xfd\xff\x07\x00\x07I\x00\x00\xe5\xf9\xa5\xa5\xc0\x08\x19\xfd[\x00\xf78\x8e\x1cFk\x01\x04\xfdr\x00\x83\n\xf9\x05\tn\x02\x05\xbev\x00\x03\x12\x8f\x00\x01\x06\x90\x00\x01\xd1g\x00\x01\xca\xd8e\x01\x9f]\x02\x90\xbav\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01\xfc\x8ee\xb4\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe3\x01\xbc\x03\xc3\x0b\x03\x08@\x0c\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf2\xb8\x10\x00B\xd1\x059&+\x01\x00\x80\xa5\xc8\x02\x07\x0b\x90\x08\xa0\x08 \x0c\x90\x1f`\x1e\xd0\xc7\x00B\x0c\x01\xdcA0\x04(&\x10\x01`@x&\x98\x1f@\x01\xa0\r\x98\x03p\x13\x02\x06\x0b\x06\xe3\x05\xcd\x07s\x00r\x05\x14\x00w\x05\xf5\x01\x16\x00L\x02J\x02B\x01B\x013\x01\x16\x00\x99\x00\x00\x00\x9a\x00\x00\x00\xa2\xda\x1f\x00X\xfb\x14\x02c\x01\x10\x00\xca\x08\xc6/\x13\x06&\xfd\xff\x00\x15\x04\x06\x00\x00\x00%\r*\x05\xbf\x05\xe1\x01e\x01\x99\x02\xfd\xff\x00\x00\xff\xff\x07\xd6\x00\x00\xa3\xda\xa5\xa5\x08\x19\xfd\x91\x00\xf7\xda\x8e\x1cF\xae\x01\x04\xfdr\x00\x83\n\xf9\x05$n\x02\x05\xbev\x00\x03\x12\x8f\x00\x01H\x91\x00\x01\xd1g\x00\x01A\xd9e\x01\x9f]\x02\x90\xbav\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01\xfc\x8ee\xb7\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe3\x01\xbb\x03\xbe\x0b\x04\x08\xd0\x0c\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xb9\x10\x00S\xd1\x05X&+\x01\x00\xfa\xa8\xc8\x02\x07\x0b@\t@\t\xb0\x0c  \xe0\x1e\xe0\xc7\xdeB\x10\x01\x10B@\x04(&\x10\x01\xb8@\x10&\xa0\x1fH\x01\xa0\r\x98\x03p\x13\x01\x06\r\x06\xdc\x05\xca\x07l\x00v\x05\x16\x00w\x05\xf5\x01\x19\x00M\x02J\x02B\x01C\x013\x01\x17\x00\xa1\x00\x00\x00\xa6\x00\x00\x00\x19\xdf\x1f\x00Q\xfb\xeb\x01<\x01\r\x00\xca\x08\xc6/\x14\x07&\xfc\x00\x00\x15\x04\x06\x00\x00\x00%\r*\x05\xbf\x05\x19\x01\x8b\x00w\x02\xfd\xff\x00\x00\x00\x00\x07x\x00\x00\x88z\xa5\xa5\x08\x19\xfaJ\x00\xf7\xed\xc4\x1eF\xe0\x00\x04\xfdi\x00\xc5\n\x11\x06\x81\xcc\x02\x05\xd5v\x00\x03\x12\x8f\x00\x01\x89\xfc\x00\x01\xd1g\x00\x01\x9de\x00\x01?Y\x02\x90\xb6v\x00\x18\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\xc5\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe0\x01\x0c\x03\xdc\x0b\x04\x08`\x05\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x91\x10\r\x00d\t\x06V^8\x01\x00\xf4\x17\xe6\x02\x07\x0b\xf0\x01\xb0\x01\x00\x05\x90\x19\x90\x18\xb0\xc6\xff7`\x01\x18B \x04\x10&H\x01\x80@@+\x80\x1f@\x01\xa0\rP\x03p\x13\x00\x06\x03\x06\xd7\x05\xbf\x07\x99\x00o\x05\x17\x00v\x05\xf5\x01\x05\x00L\x02J\x02>\x01>\x013\x01\x0f\x00\x07\x01\x00\x00\\\x00\x00\x00\xd2\xa2\x1f\x00g\xfb\x17\x02\x86\x03p\x00\xca\x08\xc7/\n\x04\'\xfd\xff\x00\x1a\x04\x06\x00\x00\x00\x08\x03\xae\x04\xa8\x04\xf2\x02\r\x04\x82\xfc\xfc\xff\x00\x00\x00\x00\x07\x8b\x00\x00ra\xa5\xa5\xc0\x00\x9a\x92\x00\xb0\xa6d`\x86\xa2@@@@\xe1\x03\xf0\x08\x19\xc1o\x00\xf7\xf14\xd6EG\x02\n\x86K\x00\x0c\x00\x01\x00.t\x01\x030\x03\x00\x03y\x00\x00\x01\xfa\xc7\x10\x01\x03\x00\x00\x01Z\x80\x04\x01\x00\x00\x00\x92\x00\x00\x00!\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00_\x00G\x13\x00\x00\n\x80\xf6\x01\xe2\x03\xd3\x0b\x06\x08\x90\x18\x05\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x8e\x01\x13\x00m\x00\x00d\x88\x01\x00\x00\xac%\x01\x00\x07\x0b \x17@\x15\x90\x15\x80\x17@\x18\xe0\xceXa\x08\x00x\x07\x08\x00\x80\x06\x08\x000\x06\x18\x00P 0\x01\x90\r\x18\x00x\x13M\x05D\x05Q\x05\t\x08\x14\x00\x9e\x05l\x00\xa0\x05\xf3\x01\\\x00O\x02R\x02S\x01S\x013\x01\x00\x00\x08\x01\x00\x00~\x00\x00\x00\xcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/ \x12\xd8\x00\x00\x00\x05\x07\x02\x00\x00\x00\'\x06\x00\x00\t\x06\x00\x00\x00\x00\x00\x00\xfc\xff\xfd\xff\x07\x00\x07I\x00\x00\xe5\xf9\xa5\xa5\xc0\x00\x86\xa2@@@@`\x9a\x92\x9c\xb0\xa6\xa6\xe1\x03\xf0\x08\x19\xdd\x04\x00\xf7\x1f?)FE\x03\x02\xd6\xe1\x00\x1c\x00\x0b\x00\xea\x86\x04\x05\x03\x94\x00\x03\x12\x8f\x00\x01\xb3\x0f\x00\x01\xd1g\x00\x01`\xc7\x06\x01\x00\x00\x00\x90\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x9f\x00\x00\x00\x00U\x13\x00\x00\x05\x80\xe1\x01\xb9\x03\xc3\x0b\x02\x08 \xfe\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x16\x0b\x00\x9d\x08\x00a\x9d\x05\x00\x00\xa4\xe6\r\x00\x07\x0bp\xfd\x10\xf9@\xfc\x90\x0c`\x0bp\xc7w5\x00\x01XDH\x04 &\xe8\x00\xc8C\xa0$\x90\x1f8\x01\xa0\r\x18\x00\x80\x13\xbd\x05\xdc\x05\xb0\x05\xc0\x07\xb4\x00_\x05\x15\x00\\\x05\xf5\x01\xed\x03K\x02I\x028\x019\x013\x01\x00\x00\x00\x00\x00\x006\x00\x00\x00\xabn\x17\x00#&x&\x00\x00\x00\x00\x00\x00\xc7/\x03\x01\'\xff\xff\x00\x0c\x13\x02\x00\x00\x009\x05d\x05t\x04\x92\x01\xe9\x00q\x03\xec\xff\xff\xff\xff\xff\x07"\x00\x00\xccC\xa5\xa5\xc0\x86\xa2@@@@`\x9a\x92\x9c\xb0\xa6\xa6\xe1\x03\xf0\x08\x19\xc6\x16\x00\xf7\x86\xf97F`\x01\x01\x00K\x00\xba\x00\xc9\x00t\xfc\x00\x05\xa2\x94\x00\x03\x12\x8f\x00\x01d\x93\x03\x01\xd1g\x00\x01\xfej\x0f\x01f\x9b\x00\x90\x80\x94\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01o\xd4\x0e\x00\x00\x00\x00\x00U\x13\x00\x00\x05\x80\xc7\x01\x85\x03\xd5\x0b\x02\x080E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12L%\x00\t~\x01r#<\x00\x00\xe2\x9f\xda\x01\x07\x0b\xe0<\xb0F\x00A\xf0<0<0\xbbx\x10\x08\x00h\x05h\x00\xa8!\xa0\x01\x80"\xb8\tX\x1d\x08\x01\xa8\r(\x00\x80\x13\xa0\x0b\xa6\x07\x00\x08\x85\x075\x00\x91\x05\x15\x00\x91\x05\xf6\x01\xb7\x00|\x01\x00\x00g\x01h\x013\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/\x0c\r\xd8\x00\x00\x00\x03\t\x01\x00\x00\x00\xa8\x07\xbc\x0b\xd0\x08\x00\x00\x00\x00\x00\x00\xa4\x02\x1e\xfe\xb2\xfd\x07$\x00\x00\xac\xc3\xa5\xa5\r\n--710071eb200fc5f402d3a45b71e8289b--\r\n'

and for Windows 10 (which doesn't work):

In [4]: prep.method
Out[4]: 'POST'
In [5]: prep.url
Out[5]: 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
In [6]: prep.headers
Out[6]: {'Content-Length': '2110', 'Content-Type': 'multipart/form-data; boundary=b265e5a28299261d61cd62ccd90fc9cc'}
In [8]: prep.body
Out[8]: b'--b265e5a28299261d61cd62ccd90fc9cc\r\nContent-Disposition: form-data; name="filename"; filename*=utf-8\'\'C%3A%5CUsers%5Cjmason86%5CMinXSS_Beacon_Decoder%5Coutput%5C2018-10-18T21_55_12.752626_SFJPM86_40.240_-105.2353.dat\r\n\r\n\xc0\x00\x9a\x92\x00\xb0\xa6d`\x86\xa2@@@@\xe1\x03\xf0\x08\x19\xc1o\x00\xf7\xf14\xd6EG\x02\n\x86K\x00\x0c\x00\x01\x00.t\x01\x030\x03\x00\x03y\x00\x00\x01\xfa\xc7\x10\x01\x03\x00\x00\x01Z\x80\x04\x01\x00\x00\x00\x92\x00\x00\x00!\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00_\x00G\x13\x00\x00\n\x80\xf6\x01\xe2\x03\xd3\x0b\x06\x08\x90\x18\x05\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x8e\x01\x13\x00m\x00\x00d\x88\x01\x00\x00\xac%\x01\x00\x07\x0b \x17@\x15\x90\x15\x80\x17@\x18\xe0\xceXa\x08\x00x\x07\x08\x00\x80\x06\x08\x000\x06\x18\x00P 0\x01\x90\r\x18\x00x\x13M\x05D\x05Q\x05\t\x08\x14\x00\x9e\x05l\x00\xa0\x05\xf3\x01\\\x00O\x02R\x02S\x01S\x013\x01\x00\x00\x08\x01\x00\x00~\x00\x00\x00\xcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/ \x12\xd8\x00\x00\x00\x05\x07\x02\x00\x00\x00\'\x06\x00\x00\t\x06\x00\x00\x00\x00\x00\x00\xfc\xff\xfd\xff\x07\x00\x07I\x00\x00\xe5\xf9\xa5\xa5\xc0\x08\x19\xfd[\x00\xf78\x8e\x1cFk\x01\x04\xfdr\x00\x83\n\xf9\x05\tn\x02\x05\xbev\x00\x03\x12\x8f\x00\x01\x06\x90\x00\x01\xd1g\x00\x01\xca\xd8e\x01\x9f]\x02\x90\xbav\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01\xfc\x8ee\xb4\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe3\x01\xbc\x03\xc3\x0b\x03\x08@\x0c\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf2\xb8\x10\x00B\xd1\x059&+\x01\x00\x80\xa5\xc8\x02\x07\x0b\x90\x08\xa0\x08 \x0c\x90\x1f`\x1e\xd0\xc7\x00B\x0c\x01\xdcA0\x04(&\x10\x01`@x&\x98\x1f@\x01\xa0\r\x98\x03p\x13\x02\x06\x0b\x06\xe3\x05\xcd\x07s\x00r\x05\x14\x00w\x05\xf5\x01\x16\x00L\x02J\x02B\x01B\x013\x01\x16\x00\x99\x00\x00\x00\x9a\x00\x00\x00\xa2\xda\x1f\x00X\xfb\x14\x02c\x01\x10\x00\xca\x08\xc6/\x13\x06&\xfd\xff\x00\x15\x04\x06\x00\x00\x00%\r*\x05\xbf\x05\xe1\x01e\x01\x99\x02\xfd\xff\x00\x00\xff\xff\x07\xd6\x00\x00\xa3\xda\xa5\xa5\x08\x19\xfd\x91\x00\xf7\xda\x8e\x1cF\xae\x01\x04\xfdr\x00\x83\n\xf9\x05$n\x02\x05\xbev\x00\x03\x12\x8f\x00\x01H\x91\x00\x01\xd1g\x00\x01A\xd9e\x01\x9f]\x02\x90\xbav\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01\xfc\x8ee\xb7\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe3\x01\xbb\x03\xbe\x0b\x04\x08\xd0\x0c\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xb9\x10\x00S\xd1\x05X&+\x01\x00\xfa\xa8\xc8\x02\x07\x0b@\t@\t\xb0\x0c  \xe0\x1e\xe0\xc7\xdeB\x10\x01\x10B@\x04(&\x10\x01\xb8@\x10&\xa0\x1fH\x01\xa0\r\x98\x03p\x13\x01\x06\r\x06\xdc\x05\xca\x07l\x00v\x05\x16\x00w\x05\xf5\x01\x19\x00M\x02J\x02B\x01C\x013\x01\x17\x00\xa1\x00\x00\x00\xa6\x00\x00\x00\x19\xdf\x1f\x00Q\xfb\xeb\x01<\x01\r\x00\xca\x08\xc6/\x14\x07&\xfc\x00\x00\x15\x04\x06\x00\x00\x00%\r*\x05\xbf\x05\x19\x01\x8b\x00w\x02\xfd\xff\x00\x00\x00\x00\x07x\x00\x00\x88z\xa5\xa5\x08\x19\xfaJ\x00\xf7\xed\xc4\x1eF\xe0\x00\x04\xfdi\x00\xc5\n\x11\x06\x81\xcc\x02\x05\xd5v\x00\x03\x12\x8f\x00\x01\x89\xfc\x00\x01\xd1g\x00\x01\x9de\x00\x01?Y\x02\x90\xb6v\x00\x18\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\xc5\x00\x00\x00\x00O\x13\x00\x00\x05\x80\xe0\x01\x0c\x03\xdc\x0b\x04\x08`\x05\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x91\x10\r\x00d\t\x06V^8\x01\x00\xf4\x17\xe6\x02\x07\x0b\xf0\x01\xb0\x01\x00\x05\x90\x19\x90\x18\xb0\xc6\xff7`\x01\x18B \x04\x10&H\x01\x80@@+\x80\x1f@\x01\xa0\rP\x03p\x13\x00\x06\x03\x06\xd7\x05\xbf\x07\x99\x00o\x05\x17\x00v\x05\xf5\x01\x05\x00L\x02J\x02>\x01>\x013\x01\x0f\x00\x07\x01\x00\x00\\\x00\x00\x00\xd2\xa2\x1f\x00g\xfb\x17\x02\x86\x03p\x00\xca\x08\xc7/\n\x04\'\xfd\xff\x00\x1a\x04\x06\x00\x00\x00\x08\x03\xae\x04\xa8\x04\xf2\x02\r\x04\x82\xfc\xfc\xff\x00\x00\x00\x00\x07\x8b\x00\x00ra\xa5\xa5\xc0\x00\x9a\x92\x00\xb0\xa6d`\x86\xa2@@@@\xe1\x03\xf0\x08\x19\xc1o\x00\xf7\xf14\xd6EG\x02\n\x86K\x00\x0c\x00\x01\x00.t\x01\x030\x03\x00\x03y\x00\x00\x01\xfa\xc7\x10\x01\x03\x00\x00\x01Z\x80\x04\x01\x00\x00\x00\x92\x00\x00\x00!\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00_\x00G\x13\x00\x00\n\x80\xf6\x01\xe2\x03\xd3\x0b\x06\x08\x90\x18\x05\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x8e\x01\x13\x00m\x00\x00d\x88\x01\x00\x00\xac%\x01\x00\x07\x0b \x17@\x15\x90\x15\x80\x17@\x18\xe0\xceXa\x08\x00x\x07\x08\x00\x80\x06\x08\x000\x06\x18\x00P 0\x01\x90\r\x18\x00x\x13M\x05D\x05Q\x05\t\x08\x14\x00\x9e\x05l\x00\xa0\x05\xf3\x01\\\x00O\x02R\x02S\x01S\x013\x01\x00\x00\x08\x01\x00\x00~\x00\x00\x00\xcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/ \x12\xd8\x00\x00\x00\x05\x07\x02\x00\x00\x00\'\x06\x00\x00\t\x06\x00\x00\x00\x00\x00\x00\xfc\xff\xfd\xff\x07\x00\x07I\x00\x00\xe5\xf9\xa5\xa5\xc0\x00\x86\xa2@@@@`\x9a\x92\x9c\xb0\xa6\xa6\xe1\x03\xf0\x08\x19\xdd\x04\x00\xf7\x1f?)FE\x03\x02\xd6\xe1\x00\x1c\x00\x0b\x00\xea\x86\x04\x05\x03\x94\x00\x03\x12\x8f\x00\x01\xb3\x0f\x00\x01\xd1g\x00\x01`\xc7\x06\x01\x00\x00\x00\x90\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x9f\x00\x00\x00\x00U\x13\x00\x00\x05\x80\xe1\x01\xb9\x03\xc3\x0b\x02\x08 \xfe\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x16\x0b\x00\x9d\x08\x00a\x9d\x05\x00\x00\xa4\xe6\r\x00\x07\x0bp\xfd\x10\xf9@\xfc\x90\x0c`\x0bp\xc7w5\x00\x01XDH\x04 &\xe8\x00\xc8C\xa0$\x90\x1f8\x01\xa0\r\x18\x00\x80\x13\xbd\x05\xdc\x05\xb0\x05\xc0\x07\xb4\x00_\x05\x15\x00\\\x05\xf5\x01\xed\x03K\x02I\x028\x019\x013\x01\x00\x00\x00\x00\x00\x006\x00\x00\x00\xabn\x17\x00#&x&\x00\x00\x00\x00\x00\x00\xc7/\x03\x01\'\xff\xff\x00\x0c\x13\x02\x00\x00\x009\x05d\x05t\x04\x92\x01\xe9\x00q\x03\xec\xff\xff\xff\xff\xff\x07"\x00\x00\xccC\xa5\xa5\xc0\x86\xa2@@@@`\x9a\x92\x9c\xb0\xa6\xa6\xe1\x03\xf0\x08\x19\xc6\x16\x00\xf7\x86\xf97F`\x01\x01\x00K\x00\xba\x00\xc9\x00t\xfc\x00\x05\xa2\x94\x00\x03\x12\x8f\x00\x01d\x93\x03\x01\xd1g\x00\x01\xfej\x0f\x01f\x9b\x00\x90\x80\x94\x00\x18\x00\x00\x00\x01\xd2\x06\x04\x08\x00\x00\x00\x01o\xd4\x0e\x00\x00\x00\x00\x00U\x13\x00\x00\x05\x80\xc7\x01\x85\x03\xd5\x0b\x02\x080E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12L%\x00\t~\x01r#<\x00\x00\xe2\x9f\xda\x01\x07\x0b\xe0<\xb0F\x00A\xf0<0<0\xbbx\x10\x08\x00h\x05h\x00\xa8!\xa0\x01\x80"\xb8\tX\x1d\x08\x01\xa8\r(\x00\x80\x13\xa0\x0b\xa6\x07\x00\x08\x85\x075\x00\x91\x05\x15\x00\x91\x05\xf6\x01\xb7\x00|\x01\x00\x00g\x01h\x013\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7/\x0c\r\xd8\x00\x00\x00\x03\t\x01\x00\x00\x00\xa8\x07\xbc\x0b\xd0\x08\x00\x00\x00\x00\x00\x00\xa4\x02\x1e\xfe\xb2\xfd\x07$\x00\x00\xac\xc3\xa5\xa5\r\n--b265e5a28299261d61cd62ccd90fc9cc--\r\n'

That prep.body filename*= in the Windows one looks suspicious to me.

James Paul Mason
  • 1,051
  • 1
  • 13
  • 27
  • Is anything else different between your two systems? Are you running the same version of Python? Of `requests`? – Blckknght Oct 13 '18 at 18:56
  • Same version of `requests` but slightly different build and version of python: * macOS requests version: 2.19.1 (py35_1 conda-forge) * Windows requests version: 2.19.1 (py37_0) – James Paul Mason Oct 14 '18 at 02:05
  • Created a new environment with the same exact version of python and version/build of `requests` on Windows to match on macOS. No change in the results. – James Paul Mason Oct 14 '18 at 02:28
  • you print out as bytes instead of str, try this `print(b"ok\n")` , `print("ok\n")`. btw it will get different output between sublime and cmd. – KC. Oct 14 '18 at 04:27
  • I'm printing out the same way in all operating systems, including through the same IDE (debug terminal in PyCharm), so that shouldn't account for the difference in output. – James Paul Mason Oct 14 '18 at 13:14
  • Is this over https or http? – James Oct 16 '18 at 16:04
  • 2
    Can you give us something to reproduce the behaviour? If you see a different response from the server, then it wasn't `requests` doing that, that's the server. – Martijn Pieters Oct 16 '18 at 16:14
  • I'll update the question with stuff to reproduce soon. What confuses me is that the server behaves the same way when I upload from a browser on macOS or WIndows and I'm literally running the exact same python code on both OS's but getting different results. – James Paul Mason Oct 16 '18 at 18:22
  • It's over http, not https – James Paul Mason Oct 16 '18 at 18:23
  • Updated question so there's enough to try reproducing now (I think). Let me know if not. – James Paul Mason Oct 16 '18 at 18:26
  • 1
    Using the technique described here : https://stackoverflow.com/questions/20658572/python-requests-print-entire-http-request-raw can you dump the raw request being sent from each OS and post the headers from those raw requests in your question (or use Wireshark to achieve the same) – James Oct 17 '18 at 08:13
  • 1
    Appears to work on Windows 7 for me (got `...Uploaded file '2018-10-15T11_05_06.783337_SFJPM86_40.241_-105.2353.dat'...`). Python 3.7.0, requests 2.19.1, urllib3 1.23. – Ulrich Stern Oct 17 '18 at 22:29
  • Weird that WIndows 7 has no problem. @James, I've updated my question with the results of this comparison. Definitely some differences. – James Paul Mason Oct 19 '18 at 02:32

2 Answers2

2

I initially could not replicate this problem on Windows 7 when I used filename = '2018-10-15T11_05_06.783337_SFJPM86_40.241_-105.2353.dat'. But when I used backslashes in the filename, I could replicate it, so it seems the server does not handle that backslash version well.

This version uses slashes instead of backslashes and works for me on Windows 7:

import requests
filename = 'C:/cygwin/home/Ulrich Stern/code/samples/python/2018-10-15T11_05_06.783337_SFJPM86_40.241_-105.2353.dat'
url = 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
file_to_send = {'filename': (filename, open(filename, 'rb'))}
r = requests.post(url, files=file_to_send)
print(r.text)

James Paul Mason, Martijn Pieters, and James deserve a share of the credits for figuring this out.

Ulrich Stern
  • 10,761
  • 5
  • 55
  • 76
  • That did it!!! I've run into the path separator issue so many times but it didn't occur to me this time because I thought python was handling it for me but as you said it's a limitation in the server script. Thank you! I can only award the bounty to one person but I've upvoted everyone else as well. – James Paul Mason Oct 19 '18 at 14:04
2

Just to add to Ulrich's answer, it's not necessary to include the full path in the upload, and in many cases you wouldn't want to (as you're exposing information about your local machine file structure that the server doesn't need to know).

So a generic solution to make your code run on either OS is:

import os.path
location, name = os.path.split(filename)
url = 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
file_to_send = {'filename': (name, open(filename, 'rb'))}
r = requests.post(url, files=file_to_send)
print(r.text)
James
  • 3,252
  • 1
  • 18
  • 33