On 11 September 2011 22:59, Platonides <platonides@gmail.com> wrote:
Also, I'm not sure if urllib.open() works with file:// urls, but I'd
verify it's a http or https url .
It even works without. For urllib2, you do need to use file:// urls.
valhallasw@dorthonion:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib, urllib2
>>> urllib.urlopen('/etc/passwd').readlines()
['root:x:0:0:root:/root:/bin/bash\n', (...) ,'usbmux:x:109:46:usbmux daemon,,,:/home/usbmux:/bin/false\n']
>>> urllib2.urlopen('file:///etc/passwd').readlines()
['root:x:0:0:root:/root:/bin/bash\n', (...)
Of course, it all boils back to the old motto 'never trust user input' - and be sure standard libraries are not more general than you think...
(and this is something that might have bitten more of us, including me :-))
Best,
Merlijn