0

EDIT: Solved. I removed the {} from the API key. I also added a response2 = response.read(), and returned that instead.

I've been experimenting with the full-contact API system, and everything seems to be running smoothly, except that my (valid)API key doesn't seem to want to work with the url to request from provided in the full-contact docs. Here's the code:

def jsearch():
    req = urllib.request.Request('https://api.fullcontact.com/v3/company.enrich')
    req.add_header('Authorization', 'Bearer {(my API key)}')
    data = json.dumps({
        "domain": "(company domain)"
    })

    data1 = data.encode('utf-8')

    response = urllib.request.urlopen(req, data1)
    return response

What should I do to actually return the response without receiving the error? Makes me wonder if the url I'm requesting from is invalid itself, in which case the fullcontact api documentation would be inaccurate...

Full Error:

Traceback (most recent call last)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\antho\PycharmProjects\jh\venv\Lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\antho\PycharmProjects\jobsrch\comsearch.py", line 21, in jsearch
response = urllib.request.urlopen(req, data1)
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\Lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
Nemo726
  • 21
  • 3
  • 1
    This might help (same error) : https://stackoverflow.com/a/8840451/12422518 – furkanayd Nov 30 '19 at 22:51
  • No, that issue was to escape a string in the url. I tried that already with my url and it didn't work. – Nemo726 Nov 30 '19 at 23:10
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Nov 30 '19 at 23:22
  • how looks your API key after you put it in header? I hope you don't keep chars `{}` in this header. – furas Nov 30 '19 at 23:24
  • Just added the full error – Nemo726 Nov 30 '19 at 23:26
  • I removed the {} and the 'Bearer,' and the new error is a 401 unauthorized – Nemo726 Nov 30 '19 at 23:28
  • When leaving 'Bearer', the error becomes: TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a HTTPResponse. – Nemo726 Nov 30 '19 at 23:33

1 Answers1

0

In your API's page, they have a documentation which says that you have include "companyName" as required request parameter. company-enrichment-API

companyName Required

The name of the company to search for. Common words like "Inc." will be ignored.

The domain is Querable:

domain string Queryable

The domain name of the company to lookup.

You should try different methods (such as companyName or additional params) to solve this issue, this is not code related as far as I understand from the docs.

furkanayd
  • 811
  • 7
  • 19