classification
Title: Python 3.0 beta 2 : json and urllib not working together?
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: wont fix
Dependencies: Superseder: merge json library with latest simplejson 2.0.x
View: 4136
Assigned To: Nosy List: bob.ippolito, orsenthil, pitrou, swaroopch
Priority: normal Keywords:

Created on 2008-09-03 09:15 by swaroopch, last changed 2009-04-01 05:04 by orsenthil. This issue is now closed.

Files
File name Uploaded Description Edit
yahoo_search.py swaroopch, 2008-09-03 09:15
Messages (7)
msg72379 - (view) Author: Swaroop (swaroopch) Date: 2008-09-03 09:15
Hi,

Running the attached program in Python 3.0 beta 2 gives the following error:

  File "C:\Python30\lib\json\decoder.py", line 21, in linecol
    lineno = doc.count('\n', 0, pos) + 1
TypeError: expected an object with the buffer interface

I can't figure out if there's an error in the program itself, but I
suspect this isn't working as expected.

Please let me know if there's anything I can do to help (if this is a
bug indeed).

Regards,
Swaroop
msg72380 - (view) Author: Swaroop (swaroopch) Date: 2008-09-03 09:17
Adding full traceback:

$ python yahoo_search.py
Traceback (most recent call last):
  File "yahoo_search.py", line 35, in <module>
    for result in search(query)['Result']:
  File "yahoo_search.py", line 28, in search
    result = json.load(urllib.request.urlopen(url))
  File "C:\Python30\lib\json\__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
  File "C:\Python30\lib\json\__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "C:\Python30\lib\json\decoder.py", line 322, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
  File "C:\Python30\lib\json\decoder.py", line 30, in errmsg
    lineno, colno = linecol(doc, pos)
  File "C:\Python30\lib\json\decoder.py", line 21, in linecol
    lineno = doc.count('\n', 0, pos) + 1
TypeError: expected an object with the buffer interface
msg72396 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2008-09-03 16:55
On the code against the trunk, I am getting the following error:

Traceback (most recent call last):
  File "python3k_json.py", line 38, in <module>
    for result in search(query)['Result']:
  File "python3k_json.py", line 31, in search
    result = json.load(obj)
  File "/usr/local/lib/python3.0/json/__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
  File "/usr/local/lib/python3.0/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.0/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object

Swaroop: What encoding would be the JSON File content? You can try by
passing the encoding argument to the load method. I tried latin1 and
ascii, did not help.

Few more things to note:
- The above TypeError was introduced by the fix of Issue2834.
- There are also bugs open in other modules (shutil, imaplib) where
problems with str<->bytes conversions are observed.
msg72400 - (view) Author: Swaroop (swaroopch) Date: 2008-09-03 17:08
Hi Senthil,

I am not aware of what encoding is used.

An example of the content is
http://search.yahooapis.com/WebSearchService/V1/webSearch?query=byte+of+python&appid=jl22psvV34HELWhdfUJbfDQzlJ2B57KFS_qs4I8D0Wz5U5_yCI1Awv8.lBSfPhwr&results=20&start=1&output=json

( If the above link does not work properly, please use http://is.gd/2bbI )

When viewing this, Firefox says it is UTF-8.
msg72421 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-03 21:38
If you look at the headers of HTTP response, the encoding is utf-8. You
should also be able to get this information by calling the info() method
on the return value of urlopen().
msg84981 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-04-01 05:02
This is superseded by issue4136.
msg84982 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-04-01 05:04
This is superseded by issue4136.
History
Date User Action Args
2009-04-01 05:04:41orsenthilsetstatus: open -> closed
nosy: + bob.ippolito
messages: + msg84982

2009-04-01 05:02:56orsenthilsetresolution: wont fix
superseder: merge json library with latest simplejson 2.0.x
messages: + msg84981
2008-09-03 21:38:03pitrousetnosy: + pitrou
messages: + msg72421
2008-09-03 17:08:56swaroopchsetmessages: + msg72400
2008-09-03 16:55:36orsenthilsettype: behavior
messages: + msg72396
components: + Library (Lib), - None
nosy: + orsenthil
2008-09-03 09:17:41swaroopchsetmessages: + msg72380
2008-09-03 09:15:49swaroopchcreate