Unable to Connect to Proxy for OAuth2

96 views
Skip to first unread message

Eric Shau

unread,
Jun 3, 2023, 1:16:53 AMJun 3
to FatSecret Platform API
I am using CCProxy in order to request a token through a proxy for OAuth2. My proxy numbers are here: Proxies.PNGHowever, I am encountering this error:

ProxyError: HTTPSConnectionPool(host='oauth.fatsecret.com', port=443): Max retries exceeded with url: /connect/token (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10049] The requested address is not valid in its context')))

My code is below. I have my information stored in a .env file (FATSECRET_IP  is '0.0.0.0'): 
#Load libraries
from dotenv import load_dotenv
import os
import pandas as pd
import requests

#Set up API
load_dotenv()
client_id = os.getenv('FATSECRET_CLIENT_ID')
client_secret = os.getenv('FATSECRET_CLIENT_SECRET')
proxy_ip = os.getenv('FATSECRET_IP')
proxies = {
    'http': f'http://{proxy_ip}:808',
    'https': f'http://{proxy_ip}:808'
}

grant_type = 'client_credentials'
scope = 'premier'
#Generate FatSecret Token
headers = {
    'content-type': 'application/x-www-form-urlencoded'
}
data = {
    'grant_type': grant_type,
    'scope': scope
}
auth = requests.auth.HTTPBasicAuth(client_id,
                                   client_secret)

token = requests.post(url=fs_token_url,
                      auth=auth,
                      headers=headers,
                      data=data,
                      proxies=proxies)
print(token.json())
token_string = token.json()['access_token']

seba...@fatsecret.com

unread,
Jun 4, 2023, 3:35:43 PMJun 4
to FatSecret Platform API
Hi there,

Thanks for reaching out.

Can you please ensure you have submitted your IP ranges correctly in your API account?


Kind regards,
The FatSecret Platform API Team

Eric Shau

unread,
Jun 4, 2023, 3:46:51 PMJun 4
to FatSecret Platform API
Yes I have!

I've added both 0.0.0.0 and my local machine IP address on there.

Eric Shau

unread,
Jun 7, 2023, 2:51:21 PMJun 7
to FatSecret Platform API
I got that to work now:
{'access_token': XXX, 'expires_in': 86400, 'token_type': 'Bearer', 'scope': 'premier'}

But now I have this issue even though I insert my proxies:
{'error': {'code': 21, 'message': "Invalid IP address detected: 'X.X.X.X'"}}

Here is my code:
headers = {
    'Authorization': f'Bearer {token_string}'
}
params = {
    'method': 'foods.search.v2',
    'format': 'json',
    'search_expression': 'toast'
}

requests.post(url=fs_url,
              headers=headers,
              params=params,
              proxies=proxies).json()
Reply all
Reply to author
Forward
0 new messages