This might be the reason http://www.diveinto.org/python3/porting-code-to-python-3-with-2to3.html
Specifically, the urllib library changes between python 2 and python 3. Here are the specific changes
Python 2 Python 3
import urllib import urllib.request, urllib.parse, urllib.error
import urllib2 import urllib.request, urllib.error
import urlparse import urllib.parse
import robotparser import urllib.robotparser
from urllib import FancyURLopener from urllib.request import FancyURLopener
from urllib import urlencode from urllib.parse import urlencode
from urllib2 import Request from urllib.request import Request
from urllib2 import HTTPError from urllib.error import HTTPError
As far as I can tell there is no way to avoid this without parsing of some kind - if you want to pursue that method then isort
(as suggested in the comments to your question) is likely your best bet. Alternatively you could parse the code on your own, or just accept that you can't easily fix this issue and it is unlikely to cause any real problems in your code.