colonelpanic8/okcupyd

Error in JSON search

ageis opened this issue · 19 comments

ageis commented

Using 1.0.0a3.

Given a very simple search:

    profiles = user.search(age_min=26, age_max=38, gentation='women who like men', last_online='month', order_by='match', radius=15, location='san francisco, ca', number=10)
    print '\n'.join(profiles)

I get this back from OKCupid:

{"error" : {"message" : "missing json value.", "type" : "ParseJSON"}}

And the following traceback:

Traceback (most recent call last):
  File "./okc.py", line 10, in <module>
    print '\n'.join(profiles)
  File "/usr/local/lib/python2.7/dist-packages/okcupyd/util/fetchable.py", line 164, in _make_nice_repr_iterator
    for item in original_iterable:
  File "/usr/local/lib/python2.7/dist-packages/okcupyd/json_search.py", line 54, in fetch
    for profile in self.fetch_once(count=count):
  File "/usr/local/lib/python2.7/dist-packages/okcupyd/json_search.py", line 59, in fetch_once
    after=self._last_after, count=count
  File "/usr/local/lib/python2.7/dist-packages/okcupyd/json_search.py", line 107, in fetch
    response = self._session.okc_post(**request_parameters)
  File "/usr/local/lib/python2.7/dist-packages/okcupyd/session.py", line 130, in okc_method
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error:  for url: https://www.okcupid.com/apitun/match/search?access_token=redacted

Hmmm. They probably update their api again. I would using chrome developer tools to see what the search json request looks like. Its probably just a matter of sending along some additional parameters in the request body.

@ageis can you give this a spin and see if the new version fixed this?

ageis commented

@IvanMalison Nope, same error, just the URL is different and has the /1/ in it.

how did you test it so fast?

ageis commented

@IvanMalison lol, I'm just fast. I got the e-mail notification, have your repository on my computer and I git pulled and ran python setup.py install and then triggered my script.

hmmm weird. i was getting this error before and now I'm not getting it with these new commits.

oh wait can you try search without any of the params

You're still getting {"error" : {"message" : "missing json value.", "type" : "ParseJSON"}}

@ageis Oh I figured it out. order_by needs to be uppercased. I'll make a change to the filters to upcase it for you

@ageis let me know if that works for you

ageis commented

@IvanMalison My error is still:

...
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error:  for url: https://www.okcupid.com/1/apitun/match/search

Is there anything wrong with the code in the original post?

In [11]: '\n'.join(profile.username for profile in user.search(
    ...:     age_min=26,
    ...:     age_max=38,
    ...:     gentation='women who like men',
    ...:     last_online='month',
    ...:     order_by='match',
    ...:     radius=15,
    ...:     location='san francisco, ca',
    ...:     number=10
    ...: ))                                                     
2016-07-13 13:22:01 ivan-mbp requests.packages.urllib3.connectionpool[13979] INFO Starting new HTTPS con
nection (1): www.okcupid.com                                                                           
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): www.okcupid.com
2016-07-13 13:22:01 ivan-mbp requests.packages.urllib3.connectionpool[13979] DEBUG "POST /login HTTP/1.1
" 200 None                                                                                             
DEBUG:requests.packages.urllib3.connectionpool:"POST /login HTTP/1.1" 200 None
2016-07-13 13:22:01 ivan-mbp okcupyd.session[13979] DEBUG {"actionable" : false, "status" : 0, "oauth_ac
cesstoken" : "1,0,1468518892,0x6164b3388d241c83;700889f6fd62a603dfb43100690e70bd9c386d17", "userid" : "7
017931174817569923", "status_str" : "Sorry, Staff Robot had a meltdown\u2014check back later", "screenna
me" : "testing_okc_123", "thumbnail" : "https://k3.okccdn.com/php/load_okc_image.php/images/160x160/160x
160/0x2/960x963/2/3760370409699673561.webp?v=2", "show_alist_box" : null}                              

DEBUG:okcupyd.session:{"actionable" : false, "status" : 0, "oauth_accesstoken" : "1,0,1468518892,0x6164b
3388d241c83;700889f6fd62a603dfb43100690e70bd9c386d17", "userid" : "7017931174817569923", "status_str" : 
"Sorry, Staff Robot had a meltdown\u2014check back later", "screenname" : "testing_okc_123", "thumbnail"
 : "https://k3.okccdn.com/php/load_okc_image.php/images/160x160/160x160/0x2/960x963/2/376037040969967356
1.webp?v=2", "show_alist_box" : null}                                                                  

2016-07-13 13:22:01 ivan-mbp okcupyd.json_search[13979] INFO {"data": "{\"limit\": 18, \"gentation\": [\
"34\"], \"radius\": 15, \"order_by\": \"MATCH\", \"fields\": \"userinfo,thumbs,percentages,likes,last_co
ntacts,online\", \"after\": null, \"located_anywhere\": 0}", "path": "1/apitun/match/search", "headers":
 {"Content-Type": "application/json", "authorization": "Bearer 1,0,1468518892,0x6164b3388d241c83;700889f
6fd62a603dfb43100690e70bd9c386d17"}}                                                                   
INFO:okcupyd.json_search:{"data": "{\"limit\": 18, \"gentation\": [\"34\"], \"radius\": 15, \"order_by\"
: \"MATCH\", \"fields\": \"userinfo,thumbs,percentages,likes,last_contacts,online\", \"after\": null, \"
located_anywhere\": 0}", "path": "1/apitun/match/search", "headers": {"Content-Type": "application/json"
, "authorization": "Bearer 1,0,1468518892,0x6164b3388d241c83;700889f6fd62a603dfb43100690e70bd9c386d17"}}
2016-07-13 13:22:02 ivan-mbp requests.packages.urllib3.connectionpool[13979] DEBUG "POST /1/apitun/match
/search HTTP/1.1" 200 None                                                                             
DEBUG:requests.packages.urllib3.connectionpool:"POST /1/apitun/match/search HTTP/1.1" 200 None
Out[11]: u'linsey_love'

maybe it has to do with pagination? can you run okcupyd as

okcupyd eal i

or ideally

tox -e venv -- okcupyd eal i
ageis commented

@IvanMalison I really don't know what the deal is. I can't use tox here cause my tox (Debian sid) is for Python 3. I'm having what seems to be some more success with the search when using okcupyd on the command line instead of in a custom script, but I'm struggling with some type errors and other stuff.

When I do the same exact search, I get back a list with one profile in it. That doesn't seem right. When I print profiles it's one username. when I try to jump into that profile in a loop and see its attributes, i.e. print profile.gender I get list index out of range.

Shouldn't there be 10 profiles coming back?

not if there aren't 10 matches.

try running a search with fewer restrictions.

ageis commented

Getting one profile result no matter what, even if age_min and age_max are the only parameters.