nausheenfatma / python-wikitools

Automatically exported from code.google.com/p/python-wikitools
0 stars 0 forks source link

Stall on File Upload #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Short explanation of the problem:

Once a read-only file is opened and prepared to be uploaded, software stalls

>>> wfile.upload(fileobj=tmp,ignorewarnings=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/site-packages/wikitools/wikifile.py", line 228, in upload
    res = req.query()
  File "/usr/local/lib/python2.6/site-packages/wikitools/api.py", line 139, in query
    rawdata = self.__getRaw()
  File "/usr/local/lib/python2.6/site-packages/wikitools/api.py", line 214, in __getRaw
    data = self.opener.open(self.request)
  File "/usr/local/lib/python2.6/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.6/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/local/lib/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.6/urllib2.py", line 1161, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.6/urllib2.py", line 1134, in do_open
    r = h.getresponse()
  File "/usr/local/lib/python2.6/httplib.py", line 986, in getresponse
    response.begin()
  File "/usr/local/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/local/lib/python2.6/socket.py", line 397, in readline
    data = recv(1)
KeyboardInterrupt

Expected behavior:

I would expect to either get an error, which happens when the file isn't 
prepared correctly, or a success response.

Diffs of the problem (if applicable):

Original issue reported on code.google.com by douglasm...@gmail.com on 25 Jun 2010 at 8:42

GoogleCodeExporter commented 8 years ago
What do you mean when you say "read-only file"? A file that is set as read-only 
by the OS or a file opened with mode r? I tested on Linux and Windows and 
couldn't reproduce this:
>>> from wikitools import *
>>> site = wiki.Wiki('http://www.mediawiki.org/w/api.php')
>>> site.login('user', 'pass')
True
>>> wfile = wikifile.File(site, 'Test6.jpg')
>>> wfile
<wikitools.wikifile.File 'File:Test6.jpg' using 
'http://www.mediawiki.org/w/api.php'>
>>> tmp = open('Example.jpg', 'rb')
>>> wfile.upload(fileobj=tmp, ignorewarnings=True)
{u'upload': {u'result': u'Success', ...lots of stuff ...}}

The file was chmod'd to 400, and I also tested with mode r instead of rb.

Original comment by MrZmanwiki@gmail.com on 25 Jun 2010 at 11:16

GoogleCodeExporter commented 8 years ago
Actually, I think the problem was that the file was read only, but all of the 
file had been "read" by the point is was uploaded. Once I got rid of the 'read' 
line, it worked, but it took a while to realize what the problem was. The 
stalling was a red herring!

Original comment by douglasm...@gmail.com on 26 Jun 2010 at 2:14

GoogleCodeExporter commented 8 years ago
Yes, that's correct, it needs to be at the beginning of the file. I've changed 
it in r349 to reset to the beginning of the file. 

Original comment by MrZmanwiki@gmail.com on 26 Jun 2010 at 4:12