4

Closed

urllib2.urlopen fails: TypeError: create_connection() takes at most 2 arguments (3 given)

description

When trying to request a URL using urllib2, the call fails with this exception:
 
IronPython 2.7 Alpha 1 (2.7.0.1) on .NET 4.0.30319.1
Type "help", "copyright", "credits" or "license" for more information.
import urllib
import urllib2
urllib2.urlopen("http://microsoft.com")
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 126, in urlopen
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 391, in open
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 408, in _open
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 369, in _call_chain
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 1173, in http_open
File "C:\Program Files (x86)\IronPython 2.7\Lib\urllib2.py", line 1142, in do_open
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 940, in endheaders
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 803, in _send_output
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 755, in send
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 735, in connect
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 946, in request
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 987, in _send_request
TypeError: create_connection() takes at most 2 arguments (3 given)
 
System:
Windows XP x64
IronPython 2.7 Alpha 1
Visual Studio 2010
 
I was able to work around the problem by modifying the calls to create_connection in httplib (lines: 735, 1151):
 
Change:
self.sock = socket.create_connection((self.host,self.port),
                                         self.timeout, self.source_address)
 
To:
 
self.sock = socket.create_connection((self.host,self.port),
                                         self.timeout)
Closed Dec 20, 2010 at 5:55 PM by jdhardy
This is fixed in 2.7B1:IronPython 2.7 Beta 1 (2.7.0.10) on .NET 4.0.30319.1Type "help", "copyright", "credits" or "license" for more information.>>> import urllib2>>> urllib2.urlopen('http://microsoft.com/')<addinfourl at 43 whose fp = <open file 'nul', mode 'rb' at 0x0075AB8B>>

comments