-1

Mod security blocks me from accessing a URL.

I have tried using other methods from this website, but none seem to work as I use an import called PyCurrency-Calculator

import PyCurrency_Converter
import urllib.request
from bs4 import BeautifulSoup

PyCurrency_Converter.convert(1, 'USD', 'A$')

The error is:

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
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
  • I think `PyCurrency_Converter` gets its data from a webpage, which is probably down or not accepting requests for some reason. I think a fix should come from the developer of the library. However, there are alternatives for a currency converter. Try [CurrencyConverter](https://pypi.org/project/CurrencyConverter/). – funie200 Jun 06 '19 at 06:26
  • 2
    The underlying request would look like [this](https://finance.google.com/finance/converter?a=1&from=USD&to=A$) its a [403](https://en.wikipedia.org/wiki/HTTP_403) and error text is `We're sorry...... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.` Also see [this](https://stackoverflow.com/questions/49366919/google-finance-api-giving-403-error). PyCurrency_Converter is hardcoded to use that google finance uri, so you probably want to use another library or make the http request yourself to another service. – Paul Rooney Jun 06 '19 at 06:27

1 Answers1

0

PyCurrency_Converter makes a call google finance under the hood (code). This service is no longer available and so the library needs to be modified to use a different service.

What you can do is find an alternative web based api and call that (I have no recommendation). As you can see the code for PyCurrency_Converter is quite short, so it will be simple to take and adapt it to another currency conversion api or to use requests or urllib to just do the requests yourself.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61