Mod安全性阻止了我访问URL。
我尝试过使用此网站上的其他方法,但是似乎没有任何作用,因为我使用了名为PyCurrency-Calculator
的导入
import PyCurrency_Converter
import urllib.request
from bs4 import BeautifulSoup
PyCurrency_Converter.convert(1, 'USD', 'A$')
错误是:
Traceback (most recent call last):
File "E:/Downloads/list of currencies.py", line 7, in <module>
PyCurrency_Converter.convert(1, 'USD', 'A$')
File "E:\Python34\lib\site-packages\PyCurrency_Converter\PyCurrency.py",
line 48, in convert
return PyCurrency.convert(amount, _from, _to)
File "E:\Python34\lib\site-packages\PyCurrency_Converter\PyCurrency.py",
line 31, in convert
response = urllib2.urlopen(url)
File "E:\Python34\lib\urllib\request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "E:\Python34\lib\urllib\request.py", line 469, in open
response = meth(req, response)
File "E:\Python34\lib\urllib\request.py", line 579, in http_response
'http', request, response, code, msg, hdrs)
File "E:\Python34\lib\urllib\request.py", line 507, in error
return self._call_chain(*args)
File "E:\Python34\lib\urllib\request.py", line 441, in _call_chain
result = func(*args)
File "E:\Python34\lib\urllib\request.py", line 587, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
答案 0 :(得分:0)
PyCurrency_Converter
在后台(code)致电Google财经。该服务不再可用,因此需要修改库以使用其他服务。
您可以做的是找到一个替代的基于Web的api并进行调用(我不建议)。如您所见,PyCurrency_Converter
的代码很短,因此可以很容易地将其适应另一个货币转换api或使用请求或urllib自行完成请求。