0

编辑:解决。我从 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

我应该怎么做才能在没有收到错误的情况下实际返回响应?让我想知道我请求的 url 本身是否无效,在这种情况下,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
4

1 回答 1

0

在您的 API 页面中,他们有一个文档说明您已将“companyName”作为必需的请求参数包含在内。公司浓缩API

公司名称 必填

要搜索的公司名称。像“Inc.”这样的常用词。将被忽略。

域是可查询的:

字符串可查询

要查找的公司的域名。

您应该尝试不同的方法(例如 companyName 或附加参数)来解决此问题,据我从文档中了解,这与代码无关。

于 2019-12-01T00:36:32.480 回答