Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'GraphServiceClient' from partially initialized module 'msgraph' (most likely due to a circular import) #918

Closed
nakasix opened this issue Oct 3, 2024 · 1 comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

Comments

@nakasix
Copy link

nakasix commented Oct 3, 2024

Describe the bug

I would like to test msgraph but when i try the following sample https://github.com/microsoftgraph/msgraph-sdk-python?tab=readme-ov-file#3-make-requests-against-the-service.

I get this error at execution: ImportError: cannot import name 'GraphServiceClient' from partially initialized module 'msgraph' (most likely due to a circular import)

Expected behavior

Correct execution of script with return of /me call.

How to reproduce

  1. Initialize a project with Poetry
  2. Add package msgraph-sdk
  3. Excute script over poetry

The script is (little modification from sample):

# coding: utf-8

# Dependencies
import asyncio
from azure.identity import InteractiveBrowserCredential
from msgraph import GraphServiceClient
import json

with open("configurations/configuration.json", encoding="utf-8") as obj_text_io_wrapper:
    dct_configuration = json.load(obj_text_io_wrapper)

credential = InteractiveBrowserCredential(
    client_id=dct_configuration["client_id"],
    tenant_id=dct_configuration["tenant_id"],
)
scopes = dct_configuration["scopes"]
client = GraphServiceClient(credentials=credential, scopes=scopes)

# GET /me
async def me():
    me = await client.me.get()
    if me:
        print(me.display_name)
asyncio.run(me())

SDK Version

1.9.0

Latest version known to work for scenario above?

No response

Known Workarounds

For the moment, I make my own calls using MSAL and call APIs on graph.microsoft.com.

Debug output

No response

Configuration

OS: WSL2 with Ubuntu 24.04.1 LTS
Poetry: 1.8.2 (Python 3.12.3)
Packages:

aiohappyeyeballs                        2.4.3       Happy Eyeballs for asyncio
aiohttp                                 3.10.8      Async http client/server framework (asyncio)
aiosignal                               1.3.1       aiosignal: a list of registered asynchronous callbacks
anyio                                   4.6.0       High level compatibility layer for multiple asynchronous event loop implementations
attrs                                   24.2.0      Classes Without Boilerplate
azure-core                              1.31.0      Microsoft Azure Core Library for Python
azure-identity                          1.18.0      Microsoft Azure Identity Library for Python
certifi                                 2024.8.30   Python package for providing Mozilla's CA Bundle.
cffi                                    1.17.1      Foreign Function Interface for Python calling C code.
charset-normalizer                      3.3.2       The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
cryptography                            43.0.1      cryptography is a package which provides cryptographic recipes and primitives to Python developers.
deprecated                              1.2.14      Python @deprecated decorator to deprecate old python classes, functions or methods.
frozenlist                              1.4.1       A list-like structure which implements collections.abc.MutableSequence
h11                                     0.14.0      A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
h2                                      4.1.0       HTTP/2 State-Machine based protocol implementation
hpack                                   4.0.0       Pure-Python HPACK header compression
httpcore                                1.0.6       A minimal low-level HTTP client.
httpx                                   0.27.2      The next generation HTTP client.
hyperframe                              6.0.1       HTTP/2 framing layer for Python
idna                                    3.10        Internationalized Domain Names in Applications (IDNA)
importlib-metadata                      8.4.0       Read metadata from Python packages
microsoft-kiota-abstractions            1.3.3       Core abstractions for kiota generated libraries in Python
microsoft-kiota-authentication-azure    1.1.0       Authentication provider for Kiota using Azure Identity
microsoft-kiota-http                    1.3.3       Kiota http request adapter implementation for httpx library
microsoft-kiota-serialization-form      0.1.1       Implementation of Kiota Serialization Interfaces for URI-Form encoded serialization
microsoft-kiota-serialization-json      1.3.3       Implementation of Kiota Serialization interfaces for JSON
microsoft-kiota-serialization-multipart 0.1.0       Implementation of Kiota Serialization Interfaces for Multipart serialization
microsoft-kiota-serialization-text      1.0.0       Implementation of Kiota Serialization interfaces for text/plain
msal                                    1.31.0      The Microsoft Authentication Library (MSAL) for Python library enables your app to access the Microsoft Cloud by supporting authentication ...
msal-extensions                         1.2.0       Microsoft Authentication Library extensions (MSAL EX) provides a persistence API that can save your data on disk, encrypted on Windows, mac...
msgraph-core                            1.1.5       Core component of the Microsoft Graph Python SDK
msgraph-sdk                             1.9.0       The Microsoft Graph Python SDK
multidict                               6.1.0       multidict implementation
opentelemetry-api                       1.27.0      OpenTelemetry Python API
opentelemetry-sdk                       1.27.0      OpenTelemetry Python SDK
opentelemetry-semantic-conventions      0.48b0      OpenTelemetry Semantic Conventions
pendulum                                3.0.0       Python datetimes made easy
portalocker                             2.10.1      Wraps the portalocker recipe for easy usage
pycparser                               2.22        C parser in Python
pyjwt                                   2.9.0       JSON Web Token implementation in Python
python-dateutil                         2.9.0.post0 Extensions to the standard Python datetime module
requests                                2.32.3      Python HTTP for Humans.
six                                     1.16.0      Python 2 and 3 compatibility utilities
sniffio                                 1.3.1       Sniff out which async library your code is running under
std-uritemplate                         2.0.0       std-uritemplate implementation for Python
typing-extensions                       4.12.2      Backported and Experimental Type Hints for Python 3.8+
tzdata                                  2024.2      Provider of IANA time zone data
urllib3                                 2.2.3       HTTP library with thread-safe connection pooling, file post, and more.
wrapt                                   1.16.0      Module for decorators, wrappers and monkey patching.
yarl                                    1.13.1      Yet another URL library
zipp                                    3.20.2      Backport of pathlib-compatible object wrapper for zip files

Other information

Regards ;)

@nakasix nakasix added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Oct 3, 2024
@nakasix
Copy link
Author

nakasix commented Oct 4, 2024

Hello,

I'm terribly sorry. The circular import came from the fact that my script was called msgraph.py. How could I have missed this...

Regards,

@nakasix nakasix closed this as completed Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

1 participant