编辑:已解决。 我从API密钥中删除了{}。 我还添加了response2 = response.read(),并将其返回。
我一直在尝试使用全接触式API系统,并且一切似乎都运行顺利,只是我的(有效)API密钥似乎不希望使用完整提供的url进行请求-联系文档。 这是代码:
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
我应该怎么做才能真正返回响应而不收到错误?让我想知道我从中请求的网址本身是否无效,在这种情况下,fullcontact api文档将不准确...
完全错误:
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
答案 0 :(得分:0)
在您的API页面上,他们有一个文档,其中说您包括“ companyName”作为必需的请求参数。 company-enrichment-API
公司名称 必需
要搜索的公司名称。常用词,例如“ Inc.”。将被忽略。
域是可查询的:
域字符串可查询
要查找的公司的域名。
您应该尝试其他方法(例如companyName或其他参数)来解决此问题,据我从文档中了解,这与代码无关。