My first post/question to stackoverflow, please bear with me.
Project/Objective:
I have a python script on pythonanywhere which uses an API get request which requires an ip specific key. However, when the script is run from pythonanywhere, the ip is dynamic. I am able to work around using an open proxy server and specifying the proxy server's ip in the request header and generating the API key with the proxy server's ip. I thought a better solution would be to set up a proxy server of my own at home.
Attempted Solution:
Running tinyproxy on ubuntu 16.04 behind a router with port forwarding set on 8888 to the internal ip of the ubuntu machine.
tinyproxy config settings as follows:
Port 8888
ConnectPort 443
ConnectPort 563
Allow 127.0.0.1
Allow xx.xx.xx.xx (my external ip)
Allow 192.168..0.0/16
Sample Code:
import requests
proxy_ip = 'xx.xx.xx.xx:8888' # my external ip
proxy = {
'http': proxy_ip,
'https': proxy_ip
}
r = requests.get('https://api.ipify.org',params={'format': 'json'},proxies=proxy)
my_proxied_ip = r.json()['ip']
print('my proxied ip: ' + my_proxied_ip)
Problem:
If I use a known open proxy ip:port... works fine.
If I xx.xx.xx.xx:8888... I get:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: /?format=json (Caused
by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Access denied',)))
Question:
I am striking out with troubleshooting... seems like it's a problem with the proxy server (tinyproxy) settings. Or is there something else I'm missing? Or a better solution / workaround?