clearbit / clearbit-python

Clearbit Python library

Home Page:https://clearbit.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discover API errors with unexpected keyword argument 'json'

MarkAWard opened this issue · comments

I tried running the example from the docs (and other queries as well to this endpoint)

clearbit.Discovery.search(
  query={'tech': 'marketo', 'raised': '100000~'},
  sort='alexa_asc'
)

and i get an error from requests library saying: TypeError: request() got an unexpected keyword argument 'json'

clearbit package requirements are requests >= 0.8.8 and I am using requests==1.0.4 but the json parameter was added to requests in version 2.4.2. Upgrading the requirement version number would not be the right solution, I may suggest using the 'data' kwarg instead and encode the payload. But as a side note as well I noticed that this is making a POST while the docs have it as a GET...

When I tried to test this out though I still could not get a valid response but I may be doing something incorrect (same result when get is a post too)

endpoint = 'https://discovery.clearbit.com/v1/companies/search'
>>> resp = requests.get(endpoint, auth=(<key>, ''), 
                                data=json.dumps({"query": {"raised": "100000~", "tech": "marketo"}})
                                )
>>> resp.json()
{u'error': {u'message': u'"query" param is required. Check https://clearbit.com/docs.',
  u'type': u'validation'}}

This error that requests is throwing will happen for any of the other APIs that are using POST as well with an older requests version, but this was the first one I tested

I think that's because you're not seeing the Content-Type header. Out of interest, why do you think upgrading the requests version is not the right solution?

you mean by adding something like: headers={"Content-Type":"json"} that didn't seem to help either.

I just think there may be more flexible solutions that can conform to older versions and the newest version of requests. If clearbit is installed in a virtualenv where there was another package that required an older or specific version of requests (maybe for a terrible reason on their part) then they can all play together nicely. I don't have any concrete examples at the moment but I think I remember hitting an issue once upon a time where downgrading requests solved all errors. Sorry I don't have any good example will let you know if I actually find a better reason

The content type is 'application/json'

ahhh of course. yep that works my bad

if I find the time I can work on a PR with suggested edits