Python urllib2 file upload problems

后端 未结 3 2024
悲哀的现实
悲哀的现实 2020-12-29 15:47

I\'m currently trying to initiate a file upload with urllib2 and the urllib2_file library. Here\'s my code:

import sys
import urllib2_file
import urllib2

UR         


        
3条回答
  •  心在旅途
    2020-12-29 16:09

    If you're using Python 2.5 or newer, urllib2_file is both unnecessary and unsupported, so check which version you're using (and perhaps upgrade).

    If you're using Python 2.3 or 2.4 (the only versions supported by urllib2_file), try running the sample code and see if you have the same problem. If so, there is likely something wrong either with your Python or urllib2_file installation.

    EDIT:

    Also, you don't seem to be using either of urllib2_file's two supported formats for POST data. Try using one of the following two lines instead:

    d = ['uploaded', open(sys.argv[1:])]
    ## --OR-- ##
    d = {'uploaded': open(sys.argv[1:])}
    

提交回复
热议问题