[Python] eTrade API - Downloaded Sample Error: onnectionResetError: [WinError 10054] An...

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I hope someone can give me a hand here. I am new to python programming, and I downloaded the eTrade API sample and trying to get it to run and I am getting this error. I have alos tried this in C# and VB.NET with no luck.

    Exception has occurred: ConnectionError
    ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
    ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

    During handling of the above exception, another exception occurred:

    urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

    During handling of the above exception, another exception occurred:

    File "C:\Users\kg5fc\Downloads\Bots\etrade_python_client.py", line 63, in oauth
    request_token, request_token_secret = etrade.get_request_token(
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\kg5fc\Downloads\Bots\etrade_python_client.py", line 111, in <module>
    oauth()


    Code snip that it errors (Last 2 lines) on:

    """This Python script provides examples on using the E*TRADE API endpoints"""
    from __future__ import print_function
    import webbrowser
    import json
    import logging
    import configparser
    import sys
    import requests
    from rauth import OAuth1Service
    from logging.handlers import RotatingFileHandler
    from accounts.accounts import Accounts
    from market.market import Market

    # loading configuration file
    config = configparser.ConfigParser()
    config.read('config.ini')

    # logger settings
    logger = logging.getLogger('my_logger')
    logger.setLevel(logging.DEBUG)
    handler = RotatingFileHandler("python_client.log", maxBytes=5*1024*1024, backupCount=3)
    FORMAT = "%(asctime)-15s %(message)s"
    fmt = logging.Formatter(FORMAT, datefmt='%m/%d/%Y %I:%M:%S %p')
    handler.setFormatter(fmt)
    logger.addHandler(handler)

    print('consumer_key: ' + config["DEFAULT"]["CONSUMER_KEY"])
    print('consumer_secret: ' + config["DEFAULT"]["CONSUMER_SECRET"])

    def oauth():
    """Allows user authorization for the sample application with OAuth 1"""
    etrade = OAuth1Service(
    name="etrade",
    consumer_key=config["DEFAULT"]["CONSUMER_KEY"],
    consumer_secret=config["DEFAULT"]["CONSUMER_SECRET"],
    request_token_url="https://api.etrade.com/oauth/request_token",
    access_token_url="https://api.etrade.com/oauth/access_token",
    authorize_url="https://us.etrade.com/e/t/etws/authorize?key={}&token={}",
    base_url="https://api.etrade.com")

    menu_items = {"1": "Sandbox Consumer Key",
    "2": "Live Consumer Key",
    "3": "Exit"}
    while True:
    print("")
    options = menu_items.keys()
    for entry in options:
    print(entry + ")\t" + menu_items[entry])
    selection = input("Please select Consumer Key Type: ")
    if selection == "1":
    base_url = config["DEFAULT"]["SANDBOX_BASE_URL"]
    break
    elif selection == "2":
    base_url = config["DEFAULT"]["PROD_BASE_URL"]
    break
    elif selection == "3":
    break
    else:
    print("Unknown Option Selected!")
    print("")

    # Step 1: Get OAuth 1 request token and secret
    request_token, request_token_secret = etrade.get_request_token(
    params={"oauth_callback": "oob", "format": "json"})


    I have googled, chatGPT, and everything I can think of to find a solution.

    Continue reading...

Compartilhe esta Página