0

Using Python 3 now so I had to adjust my code. Just wanted to download those 2 files, in case they do not exist (idea was that I do not have to download them every single time).

import urllib.request
if not  os.path.isfile("test.mat"):
    urllib.request.urlopen("http://ufldl.stanford.edu/housenumbers/test_32x32.mat", "test.mat")

if not  os.path.isfile("train.mat"):
    urllib.request.urlopen("http://ufldl.stanford.edu/housenumbers/train_32x32.mat", "train.mat")

The error I get is :

TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
johnny
  • 19,272
  • 52
  • 157
  • 259
hmmmbob
  • 1,167
  • 5
  • 19
  • 33
  • 5
    did you [look up the error message](http://stackoverflow.com/questions/5440485/typeerror-post-data-should-be-bytes-or-an-iterable-of-bytes-it-cannot-be-str)? and try out the already existing solutions? Or even [this](http://stackoverflow.com/questions/30760728/python-3-urllib-produces-typeerror-post-data-should-be-bytes-or-an-iterable-of)? – idjaw Dec 23 '16 at 17:43
  • 1
    See: http://stackoverflow.com/questions/7243750/download-file-from-web-in-python-3 – Rushy Panchal Dec 23 '16 at 17:46
  • I upvoted and change the title, even though I voted it should be closed as a duplicate. This was to instruct, yet not discourage, the OP. – johnny Dec 23 '16 at 17:56

0 Answers0