I keep receiving an API error when requesting from ameritrade api?

687 Views Asked by At

I am trying to pull Google price data from the TD Ameritrade API. It worked in the base form of anaconda but I created a new virtual environment and now it isn't working. It keeps returning this error. I have attempted "verify=false" and that does not work either. I have taken out my apikey for privacy reasons.

This is the error:

SSLError: HTTPSConnectionPool(host='api.tdameritrade.com', port=443): Max retries exceeded with url: /v1/marketdata/GOOG/pricehistory?apikey=apikey&endDate=1648780967000&startDate=1207017767000&periodType=year&period=1&frequency=1&frequencyType=weekly (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:997)')))

    import requests
    import pandas as pd
    import numpy as np
    import datetime
    import tensorflow as tf
    from numpy import loadtxt
    from keras.models import Sequential
    from keras.layers import Dense
#The prices endpoint

#define endpoint

endpoint = r"https://api.tdameritrade.com/v1/marketdata/{}/pricehistory".format('GOOG')

# define our payload

payload = {'apikey': apikey,
          'endDate':'1648780967000',
          'startDate': '1207017767000',
           'periodType': 'year',
           'period':'1',
           'frequency': '1',
           'frequencyType': 'weekly'}

#make a request
content = requests.get(url = endpoint, params = payload)

#convert it to a dictionary
data = content.json()
data

1

There are 1 best solutions below

1
On

The TD ameritrade api is a pain. I suggest using the TD api module from Areed: https://github.com/areed1192/td-ameritrade-api