ptwobrussell / Mining-the-Social-Web

The official online compendium for Mining the Social Web (O'Reilly, 2011)
http://bit.ly/135dHfs
Other
1.21k stars 491 forks source link

Ex 4.10 fails with Unexpected String or buffer #4

Closed accurateKevin closed 13 years ago

accurateKevin commented 13 years ago

I've been able to follow the examples well enough until 4.10, when line 23 id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] throws "TypeError: expected string or buffer" down in the decoder.py script.

I have friend and follower sets loaded in Redis for two screen_name handles, and I checked to make sure I'm spelling the screen name properly in my ex 4.1 script -- I checked in Komodo and it's properly loading the friend_ids list in line 22. What am I missing?

Here's the traceback:

Traceback (most recent call last): File "C:\Python27\Scripts\kevin_py_scripts\FFredis2nx.py", line 23, in id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] File "C:\Python27\lib\jsoninit.py", line 326, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 360, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

ptwobrussell commented 13 years ago

Hmm. It looks like the failure is in json.loads, so that means that we should check to see what value is keyed by the result of getRedisIdByScreenName(SCREEN_NAME, 'info.json') in redis. It should be a valid JSON value, but apparently it isn't, which makes me wonder how it got there.

Can you do these things:

1) Resolve the string value for getRedisIdByScreenName(SCREEN_NAME, 'info.json') by adding in a "print >> sys.stderr, getRedisIdByScreenName(SCREEN_NAME, 'info.json')" statement just before that line. 2) Try to inspect that value to see what it is. You might find the redis CLI utility to be helpful for this (It should be in your redis/bin directory and is pretty intuitive to work with. You'd tell it something like "get KEY" in this case.) Or, you might enter into an interactive interpreter session, connect to redis and poke around.

It could also be helpful to know the version of Redis you're using (2.x?) as well as the Redis python package. You can figure out the latter by printing out redis.file in your script.

Let me know what you discover. I'll be standing by to help in any way that I can.

Regards - Matthew


http://www.linkedin.com/in/ptwobrussell

On May 14, 2011, at 7:19 PM, accurateKevin wrote:

I've been able to follow the examples well enough until 4.10, when line 23 id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] throws "TypeError: expected string or buffer" down in the decoder.py script.

I have friend and follower sets loaded in Redis for two screen_name handles, and I checked to make sure I'm spelling the screen name properly in my ex 4.1 script -- I checked in Komodo and it's properly loading the friend_ids list in line 22. What am I missing?

Here's the traceback:

Traceback (most recent call last): File "C:\Python27\Scripts\kevin_py_scripts\FFredis2nx.py", line 23, in id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] File "C:\Python27\lib\jsoninit.py", line 326, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 360, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

Reply to this email directly or view it on GitHub: https://github.com/ptwobrussell/Mining-the-Social-Web/issues/4

accurateKevin commented 13 years ago

Hi Matthew,

Thank you for the reply. You're right about it being a problem with the content in the REDIS store -- I had been keeping it clean between examples, and have been picking and choosing among examples to learn from. When I attempted ex 4.10, all that was housed in the store were lists of friends and followers of a few accounts -- not a single JSON object to be found. I'll need to backtrack and look at the examples on loading JSON objects in the data store -- it looks like the treatment of pulling down full profiles is a good place to start.

If that doesn't make things clear I'll ping you back. If it hadn't been such a long week I would have noticed the issue on my own -- I even looked at the store with CLI to confirm there were lists loaded, and at that point is should have been painfully obvious there were no JSON objects to load.

Thanks again,

-Kevin

-----Original Message----- From: ptwobrussell [mailto:reply@reply.github.com] Sent: Sunday, May 15, 2011 1:33 PM To: kevinsharp@accurateinfo.info Subject: Re: [Mining-the-Social-Web] Ex 4.10 fails with Unexpected String or buffer (#4)

Hmm. It looks like the failure is in json.loads, so that means that we should check to see what value is keyed by the result of getRedisIdByScreenName(SCREEN_NAME, 'info.json') in redis. It should be a valid JSON value, but apparently it isn't, which makes me wonder how it got there.

Can you do these things:

1) Resolve the string value for getRedisIdByScreenName(SCREEN_NAME, 'info.json') by adding in a "print >> sys.stderr, getRedisIdByScreenName(SCREEN_NAME, 'info.json')" statement just before that line. 2) Try to inspect that value to see what it is. You might find the redis CLI utility to be helpful for this (It should be in your redis/bin directory and is pretty intuitive to work with. You'd tell it something like "get KEY" in this case.) Or, you might enter into an interactive interpreter session, connect to redis and poke around.

It could also be helpful to know the version of Redis you're using (2.x?) as well as the Redis python package. You can figure out the latter by printing out redis.file in your script.

Let me know what you discover. I'll be standing by to help in any way that I can.

Regards - Matthew


http://www.linkedin.com/in/ptwobrussell

On May 14, 2011, at 7:19 PM, accurateKevin wrote:

I've been able to follow the examples well enough until 4.10, when line 23 id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] throws "TypeError: expected string or buffer" down in the decoder.py script.

I have friend and follower sets loaded in Redis for two screen_name handles, and I checked to make sure I'm spelling the screen name properly in my ex 4.1 script -- I checked in Komodo and it's properly loading the friend_ids list in line 22. What am I missing?

Here's the traceback:

Traceback (most recent call last): File "C:\Python27\Scripts\kevin_py_scripts\FFredis2nx.py", line 23, in id_for_screen_name = json.loads(r.get(getRedisIdByScreenName(SCREEN_NAME,'info.json'))) ['id'] File "C:\Python27\lib\jsoninit.py", line 326, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 360, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

Reply to this email directly or view it on GitHub: https://github.com/ptwobrussell/Mining-the-Social-Web/issues/4

Reply to this email directly or view it on GitHub: https://github.com/ptwobrussell/Mining-the-Social-Web/issues/4#comment_1167323

ptwobrussell commented 13 years ago

Kevin - I'm assuming that you're all good now. If not, please re-open. Thanks.

accurateKevin commented 13 years ago

Russell,

Thanks, I'm good on this count. I'm encountering an annoying problem when I get a 400 (rate limit) error that doesn't happen if I catch the error with a breakpoint, but does if I let a script run at full speed. Hope to dig into that issue this week -- will post something when I have repeatable details.

Cheers,

--Kevin

-----Original Message----- From: ptwobrussell [mailto:reply@reply.github.com] Sent: Monday, June 20, 2011 9:21 AM To: kevinsharp@accurateinfo.info Subject: Re: [Mining-the-Social-Web] Ex 4.10 fails with Unexpected String or buffer (#4)

Kevin - I'm assuming that you're all good now. If not, please re-open. Thanks.

Reply to this email directly or view it on GitHub: https://github.com/ptwobrussell/Mining-the-Social-Web/issues/4#issuecomment-1403794