classification
Title: OSX proxy exceptions parse bug in urllib (crash)
Type: behavior Stage: resolved
Components: Library (Lib), macOS Versions: Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Proxy exception lookup fails on MacOS in urllib.
View: 8883
Assigned To: ronaldoussoren Nosy List: ned.deily, ronaldoussoren, wojas
Priority: normal Keywords: patch

Created on 2010-12-07 07:02 by wojas, last changed 2010-12-07 13:36 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
urllib-osx-proxy-patch.diff wojas, 2010-12-07 07:02 Patch
Messages (3)
msg123524 - (view) Author: (wojas) Date: 2010-12-07 07:02
On OSX (tested with 10.6), urllib will fail to parse the proxy exceptions configuration if no netmask is specified.

On my system the following entries have been added to the proxy exception list: '127.0.0.1' and 'localhost'. The traceback in included below.

The problem:
 * In 'm = re.match(r"(\d+(?:\.\d+)*)(/\d+)?", value)' the netmask is optional
 * But 'mask = int(m.group(2)[1:])' implicitly assumes it exists.

This can be fixed by using 32 as a default netmask if none is specified, see attached patch: 'mask = int(m.group(2)[1:]) if m.group(2) else 32'

TRACEBACK:

  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_opener.py", line 188, in open
    req = meth(req)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_http.py", line 316, in http_request
    self.rfp.read()
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_http.py", line 242, in read
    f = self._opener.open(req)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_opener.py", line 193, in open
    response = urlopen(self, req, data)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_urllib2_fork.py", line 344, in _open
    '_open', req)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_urllib2_fork.py", line 666, in <lambda>
    meth(r, proxy, type))
  File "/Users/wojas/dev/ds/lib/python2.6/site-packages/mechanize/_urllib2_fork.py", line 678, in proxy_open
    if req.get_host() and self._proxy_bypass(req.get_host()):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 1407, in proxy_bypass
    return proxy_bypass_macosx_sysconf(host)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 1379, in proxy_bypass_macosx_sysconf
    mask = int(m.group(2)[1:])
TypeError: 'NoneType' object is unsubscriptable
msg123525 - (view) Author: (wojas) Date: 2010-12-07 07:04
Forgot to set bug type (crash).
msg123533 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-12-07 08:59
The fix for this problem, originally reported in Issue8883, was released in Python 2.6.6.
History
Date User Action Args
2010-12-07 13:36:22r.david.murraysettype: crash -> behavior
stage: resolved
2010-12-07 08:59:49ned.deilysetstatus: open -> closed

superseder: Proxy exception lookup fails on MacOS in urllib.
assignee: ronaldoussoren
components: + Library (Lib), macOS, - Extension Modules

nosy: + ned.deily, ronaldoussoren
messages: + msg123533
resolution: duplicate
2010-12-07 07:04:14wojassettype: crash
messages: + msg123525
2010-12-07 07:02:42wojascreate