Lukasa / requests-ftp

An FTP transport adapter for use with the Python Requests library.
Other
69 stars 25 forks source link

fails if the host does not endswith a / #6

Closed pombredanne closed 10 years ago

pombredanne commented 10 years ago

This works:

>>> s = requests.Session()
>>> resp = s.list("ftp://mirrors.ibiblio.org/", auth=("anonymous", "me@anonymous.com",))

This fails:

>>> resp = s.list("ftp://mirrors.ibiblio.org", auth=("anonymous", "me@anonymous.com",))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\test\lib\site-packages\requests_ftp\ftp.py", line 21, in list_helper
    return self.request('LIST', url, **kwargs)
  File "c:\test\lib\site-packages\requests\sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\test\lib\site-packages\requests\sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "c:\test\lib\site-packages\requests_ftp\ftp.py", line 145, in send
    host, port, path = self.get_host_and_path_from_url(request)
  File "c:\test\lib\site-packages\requests_ftp\ftp.py", line 288, in get_host_and_path_from_url
    if path[0] == '/':
IndexError: string index out of range

It is probably best to test with startswith rather than a string index or to check if the string exists or else ;)

Lukasa commented 10 years ago

Haha, yes, good spot! :cake: I'll fix it up.

Lukasa commented 10 years ago

Fixed in f3b4cfc6f67a86a52ed9863aebb67d94c40fce9a.

Thanks again! :cake: