Skip to content
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

Discover API errors with unexpected keyword argument 'json' #17

Open
MarkAWard opened this issue Apr 26, 2016 · 5 comments
Open

Discover API errors with unexpected keyword argument 'json' #17

MarkAWard opened this issue Apr 26, 2016 · 5 comments

Comments

@MarkAWard
Copy link

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

@maccman
Copy link
Contributor

maccman commented Apr 26, 2016

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?

@MarkAWard
Copy link
Author

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

@maccman
Copy link
Contributor

maccman commented Apr 26, 2016

The content type is 'application/json'

@MarkAWard
Copy link
Author

ahhh of course. yep that works my bad

@MarkAWard
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants