这是我的News API代码,我收到代理设置错误,我猜这可能不是正确的。我需要帮助解决身份验证错误以设置代理。
代码:
from newsapi import NewsApiClient
from requests.auth import HTTPProxyAuth
# Init
api = NewsApiClient(api_key='b6d976f8d22a4dfsdfgdfgsfASAS453410c37')
http_proxy = "https://7031:Welcome1567@58.2.64.2:31"
https_proxy = "http://7031:Welcome1567@58.2.64.2:31"
ftp_proxy = "https://7031:Welcome1567@58.2.64.2:31"
proxyDict = {
"http" : http_proxy,
"https" : https_proxy,
"ftp" : ftp_proxy
}
auth = HTTPProxyAuth('username', 'mypassword')
# /v2/top-headlines
top_headlines = newsapi.get_top_headlines(q='bitcoin',
sources='bbc-news,the-verge',
category='business',
language='en',
country='us')
# /v2/everything
all_articles = newsapi.get_everything(q='bitcoin',
sources='bbc-news,the-verge',
domains='bbc.co.uk,techcrunch.com',
from_parameter='2017-12-01',
to='2017-12-12',
language='en',
sort_by='relevancy',
page=2)
# /v2/sources
sources = newsapi.get_sources()
我从输出中得到的错误是: 输出:
File "D:\anaconda3\lib\site-packages\requests\adapters.py", line 502, in send
ProxyError: HTTPSConnectionPool(host='newsapi.org', port=443): Max retries exceeded with url: /v2/top-headlines?q=bitcoin&sources=bbc-news%2Cthe-verge&language=en&country=us&category=business (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 authenticationrequired',)))