[Tracker-discuss] [issue594] Fix ImportError: cannot import name rndstr in oic_login.py

Berker Peksag metatracker at psf.upfronthosting.co.za
Thu Jun 9 02:11:28 EDT 2016


New submission from Berker Peksag:

I'm getting an import error with the latest version of oic. Here is a patch to fix this.

----------
files: oic.diff
messages: 3040
nosy: berker.peksag
priority: bug
status: unread
title: Fix ImportError: cannot import name rndstr in oic_login.py

_______________________________________________________
PSF Meta Tracker <metatracker at psf.upfronthosting.co.za>
<http://psf.upfronthosting.co.za/roundup/meta/issue594>
_______________________________________________________
-------------- next part --------------
diff --git a/extensions/oic_login.py b/extensions/oic_login.py
--- a/extensions/oic_login.py
+++ b/extensions/oic_login.py
@@ -2,22 +2,35 @@
 # For Google accounts, also attempt migration from OpenID (until 2017)
 from oic.oic.consumer import Consumer
 from oic.oic.message import RegistrationResponse
 from oic.oic.message import AuthorizationResponse
 import hashlib
 import hmac
 import random
 from UserDict import DictMixin
-from oic.oauth2 import rndstr
 from oic.utils.authn.client import CLIENT_AUTHN_METHOD
 from roundup.cgi.actions import Action
 from roundup.cgi.exceptions import *
 from roundup import password, hyperdb
 
+try:
+    from oic.oauth2 import rndstr
+except ImportError:
+    import string
+
+    def rndstr(size=16):
+        """
+        Returns a string of random ascii characters or digits
+        :param size: The length of the string
+        :return: string
+        """
+        _basech = string.ascii_letters + string.digits
+        return "".join([random.choice(_basech) for _ in range(size)])
+
 HOSTNAME='lap-le.pst.beuth-hochschule.de'
 
 consumer_config = {
     'debug': True
 }
 client_config = {
     'client_authn_method':CLIENT_AUTHN_METHOD,
 }


More information about the Tracker-discuss mailing list