0
votes

I am calling a new object to manage an Azure Resource and using the Azure python packages. While calling it, i get a maximum depth exceeded error however if I step through the code in a python shell I don't get this issue. Below is the init method

class WindowsDeployer(object):
    def __init__(self, params):
        try:
             print("executes class init")
             self.subscription_id = '{SUBSCRIPTION-ID}'
             self.vmName = params["vmName"]
             self.location = params["location"]
             self.resource_group = "{}-rg".format(self.vmName)
             print("sets variables")

             # Error is in the below snippet, while calling ServicePrincipalCredentials
            self.credentials = ServicePrincipalCredentials(
                client_id='{CLIENT-ID}',
                secret='{SECRET}',
                tenant='{TENANT-ID}'
            )

            # Does not reach here...
            print("creates a credential")
            self.client = ResourceManagementClient(self.credentials, self.subscription_id)

Instead, it exits with the following message: maximum recursion depth exceeded

I have tried to increase the recursion limit to 10000 and that has not solved the issue.

Pip freeze: azure==4.0.0 azure-common==1.1.4 azure-mgmt==4.0.0

Traceback:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/valana/Projects/wolfinterface/Code/wolfinterface/app.py", line 87, in wrap
    return f(*args, **kwargs)
File "/Users/valana/Projects/wolfinterface/Code/wolfinterface/app.py", line 134, in provision
    return provision_page(request, session)
File "/Users/valana/Projects/wolfinterface/Code/wolfinterface/provision.py", line 104, in provision_page
    deployer = WindowsDeployer(json.loads(params))
File "/Users/valana/Projects/wolfinterface/Code/wolfinterface/AzureProvision.py", line 30, in __init__
    tenant='{TENNANT-ID}'
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 453, in __init__
    self.set_token()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 478, in set_token
    proxies=self.proxies)
File "/Users/valana/Library/Python/3.6/lib/python/site-packages/requests_oauthlib/oauth2_session.py", line 221, in fetch_token
    verify=verify, proxies=proxies)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/sessions.py", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
File "/Users/valana/Library/Python/3.6/lib/python/site-packages/requests_oauthlib/oauth2_session.py", line 360, in request
    headers=headers, data=data, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
    conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 269, in create_urllib3_context
    context.options |= options
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 465, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 465, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 465, in options

The last line keeps going until it hits the recursion limit

2
what is the name of this class? If the name of this class is ServicePrincipalCredentials, you can't do this. You are telling a class to make itself make itself make itself make itself, etc. - JacobIRR
Please confirm with pip freeze what version of "msrestazure" is installed, and edit your post with that version. Also, do you an infinite stacktrace where you can put some sections to give an idea of where is the loop? - Laurent Mazuel
Indeed JacobIRR, I didn't think about this possibility :). Spydernaz, if you imported "from azure.common.credentials import ServicePrincipalCredentials" BUT you named your own class the same, that could create this kind of issue too. - Laurent Mazuel
Let's see the full Traceback - JacobIRR
@LaurentMazuel: I am not using msrestazure. How should I get the full trace? I am just using comments and exception messages - Spydernaz

2 Answers

1
votes

Thanks for the help above. The issue was with my gevent packages (not sure exactly what) however adding upgrading gevent and adding the following lines fixed it.

import gevent.monkey
gevent.monkey.patch_all()
0
votes

I had a similar problem when using the azure-storage-blob module, and adding the following lines fixed it. I do not know why. It makes me confused.

Exception:

maximum recursion depth exceeded while calling a Python object

Solution:

import gevent.monkey

gevent.monkey.patch_all()