GithubHelp home page GithubHelp logo

Comments (3)

iteratelance avatar iteratelance commented on August 26, 2024

Suggestion, wrap session object inside of method rather than the module. I believe that this would alleviate the problem.

def _request_token(client, payload):
    session = requests.session()
    session.headers.update({'user-agent': 'dwolla-v2-python %s' % version})
    res = session.post(client.token_url, data=payload)
    if _is_error(res):
        raise Error.map(res)
    token = client.Token(res.json())
    if client.on_grant is not None:
        client.on_grant(token)
    return token

Current

session = requests.session()
session.headers.update({'user-agent': 'dwolla-v2-python %s' % version})

def _request_token(client, payload):
    res = session.post(client.token_url, data=payload)
    if _is_error(res):
        raise Error.map(res)
    token = client.Token(res.json())
    if client.on_grant is not None:
        client.on_grant(token)
    return token

from dwolla-v2-python.

sausman avatar sausman commented on August 26, 2024

Hey @iteratelance, thanks for the detailed issue!

A while back we moved the session object to the module (#8) to take advantage of persistent connections and connection pooling.

Requests to www.dwolla.com and api.dwolla.com are handled in a similar way. Requests to www.dwolla.com share a connection pool, whereas requests to api.dwolla.com share a connection pool per-Token.

Does this SO issue sound like it could be what's happening? https://stackoverflow.com/questions/383738/104-connection-reset-by-peer-socket-error-or-when-does-closing-a-socket-resu/35945309#35945309

from dwolla-v2-python.

iteratelance avatar iteratelance commented on August 26, 2024

@sausman Thanks for the reply. I think it has something to do with AWS Lambda functions and how they operate. I've ran into this issue in the past when running async and threaded http request on Lambda and ultimately had to use a non threaded transport.

I'm not certain why connection polling has issues on Lambda, perhaps the underlying host might actually change from time to time, even while using a stay warm function for long running process, thus breaking the connection.

My final solution was to close the connection after getting each auth token.

from dwollav2 import auth

def auth():
    client = dwollav2.Client(
            key = config.get('DWOLLA_KEY'),
            secret = config.get('DWOLLA_SECRET'),
            environment = config.get('DWOLLA_ENV')
        )

    application_token = client.Auth.client()
    auth.session.close()
    return application_token

from dwolla-v2-python.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.