Am trying to initiate a request to an API (https://theteller.net/documentation#theTeller_Standard) but i keep getting this error. The idea is that will take details of the user and pass it to my views.py to send a request to to make payment and be redirected back to my website. This is the error
ProxyError at /vote/test/robert-yenji/
HTTPSConnectionPool(host='test.theteller.net', port=443): Max retries exceeded with url: /checkout/initiate (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))
this is my code
views.py
def nomination_payView(request, slug):
if request.method == 'GET':
model = get_object_or_404(Nomination, slug=slug)
template_name = 'Payment.html'
context = {
'nomination': model
}
return render(request, 'Payment.html', context)
elif request.method == 'POST':
amount = (str(int(request.POST['amount']) * 0.5) + '0').replace('.', '')
zeros = '0' * (12 - len(amount))
amount = zeros + amount
email = request.POST['email']
desc = request.POST['desc']
url = 'https://test.theteller.net/checkout/initiate'
transaction_id = random.randint(100000000000, 999999999999)
data = {
"merchant_id": "TTM-00000740",
"transaction_id": transaction_id,
"amount": amount,
"redirect_url": f"http://127.0.0.1:8000/process-payment/{slug}/{amount}",
"apiuser": "halotech5d525bfd6ead3",
"API_Key": "ZDQ2OGEyZDNjN2YzMDY5ZDVkY2MyM2U5YTRiMGI0N2Q=",
"email": email, # you would need to change this to the actual users email
"desc": desc, # this as well...
}
encoded = base64.b64encode(
b'halotech5d525bfd6ead3:ZDQ2OGEyZDNjN2YzMDY5ZDVkY2MyM2U5YTRiMGI0N2Q=') # change this as well
headers = {
'Content-Type': 'application/json',
'Authorization': f'Basic {encoded.decode("utf-8")}',
'Cache-Control': 'no-cache'
}
res = requests.post(url, data=json.dumps(data), headers=headers).json()
print(res['checkout_url'])
return redirect(res["checkout_url"])```
[This is the error i get ][1]
[1]: https://i.sstatic.net/KA3xZ.png
It's because pythonanywhere.com allows only a specific whitelist of sites to be accessed. Check the following link for more information: https://help.pythonanywhere.com/pages/403ForbiddenError/ You will have to upgrade your account to get unrestricted access.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With