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 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) *  |
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 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) *  |
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) *  |
Date: 2009-04-01 05:02 |
This is superseded by . |
|
|
msg84982 - (view) |
Author: Senthil Kumaran (orsenthil) *  |
Date: 2009-04-01 05:04 |
This is superseded by . |
|
|