Coder Social home page Coder Social logo

Comments (6)

davedoesdev avatar davedoesdev commented on September 13, 2024

@vifrrg thanks for letting me know, I see the issue. I'll integrate the fix.

from dxf.

davedoesdev avatar davedoesdev commented on September 13, 2024

@vifrrg I don't think we need to check len(rjson['access_token']) if we've already checked rjson['access_token']. What do you think?

from dxf.

davedoesdev avatar davedoesdev commented on September 13, 2024

I was thinking of:

diff --git a/dxf/__init__.py b/dxf/__init__.py
index 9b48aae..304daa0 100644
--- a/dxf/__init__.py
+++ b/dxf/__init__.py
@@ -305,7 +305,8 @@ class DXFBase(object):
                 r = self._sessions[0].get(auth_url, headers=headers, verify=self._tlsverify)
             _raise_for_status(r)
             rjson = r.json()
-            self.token = rjson['access_token'] if 'access_token' in rjson else rjson['token']
+            # Use 'access_token' value if present and not empty, else 'token' value.
+            self.token = rjson.get('access_token') or rjson['token']
             return self._token
 
         self._headers = headers

from dxf.

vifrrg avatar vifrrg commented on September 13, 2024

@davedoesdev

  1. As to checking length: it was my bad habbit from one of previous python version where empty string was treated as 'True' in 'if'. So the code like if(""): print("blahblahblah") was printing that "blahblahblah". This behaviour was changed long time ago and I'm still forgetting it every time. :)
    In recent python interpreters it is not really needed. You right.

  2. As to Your fix suggestion:
    Yes, it looks more compact and readable then mine. Let me check it in my environment. If it works by the right way - let`s integrate it.
    I'll let You know the result in a few hours.

from dxf.

vifrrg avatar vifrrg commented on September 13, 2024

@davedoesdev, Your fix works fine in both cases (old registry without "auth_token" and new one with empty value in it)
May be applied to next release.
Thank You.

from dxf.

davedoesdev avatar davedoesdev commented on September 13, 2024

@vifrrg released in version 7.5.3
Appreciate the fix!

from dxf.

Related Issues (20)

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.