-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ijson.parse iter_lines() returns error too many values to unpack (expected 2) #58
Comments
Just to add a bit more detail, iter_lines() seems to give the entire stream as a binary string since the JSON is not formatted with newline characters. iter_content() gives the data in a stream format returning what looks like 1 or 2 binary characters at a time. I thought ijson was able to handle a stream. Surely that stream doesn't need to be formatted? |
@raeldor my previous advice was to build something around Something like this: import ijson
import requests
class ResponseAsFileObject:
def __init__(self, url):
response = requests.get(url, stream=True)
self.data = response.iter_content(chunk_size=65536)
def read(self, n):
if n == 0:
return b''
return next(self.data, b'')
URL = 'your-url'
for prefix, event, name in ijson.parse(ResponseAsFileObject(URL)):
print(prefix, event, name) |
@raeldor please let me know if this worked so we can close this. |
There hasn't been a response in a week, and the solution worked for me, so I'm closing this. |
Apologies. I meant you get round to closing this and totally forgot. Really appreciate your help. Thank you.
Ray
… On Sep 19, 2021, at 23:33, rtobar ***@***.***> wrote:
There hasn't been a response in a week, and the solution worked for me, so I'm closing this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Me again, sorry. I'm trying to stream data from a web call directly into ijson. However, if I use...
parser=ijson.parse(cellset_response.iter_lines())
for prefix, event, value in parser:
pass
I get 'too many values to unpack (expected 2)' error. If I use iter_content() instead of iter_lines() I get 'not enough values to unpack (expected 2, got 1).
It seems I can't win. :D
The text was updated successfully, but these errors were encountered: