[Tutor] Need help with converting script using 2.6's urllib2 to Python 3.1

Richard D. Moores rdmoores at gmail.com
Mon Oct 25 19:33:11 CEST 2010


And trying 2to3.py, which I've used successfully before, gets

C:\P26Working\Finished\For2to3>2to3 -w -f urllib dollar2yen_rate_simple.py
Traceback (most recent call last):
  File "C:\P26Working\Finished\For2to3\2to3.py", line 2, in <module>
    from lib2to3.main import main
  File "C:\P26Working\Finished\For2to3\lib2to3\main.py", line 34
    except os.error, err:
                   ^
SyntaxError: invalid syntax

dollar2yen_rate_simple.py can be seen at <http://tutoree7.pastebin.com/4Aq9CuXS>

Also,

Running this code in Python 3.1:

from urllib import request
a = request.urlopen('http://www.marketwatch.com/investing/currency/CUR_USDYEN').read(20500)
b = a[19000:20500]
idx_pricewrap = b.find('pricewrap')
context = b[idx_pricewrap:idx_pricewrap+80]
idx_bgLast = context.find('bgLast')
rate = context[idx_bgLast+8:idx_bgLast+15]
print(rate)

gets

Traceback (most recent call last):
  File "c:\P31Working\test_urllib.py", line 4, in <module>
    idx_pricewrap = b.find('pricewrap')
TypeError: expected an object with the buffer interface
Process terminated with an exit code of 1

I have NO idea what that error means.

Dick


More information about the Tutor mailing list