mathsman5133 / coc.py

Python API Wrapper for Clash of Clans.
https://cocpy.readthedocs.io/en/latest/
MIT License
124 stars 41 forks source link

Coc.Utils import failing (circular import) #245

Closed SouthernCure closed 2 months ago

SouthernCure commented 2 months ago

Having trouble using coc.utils for some reason

if not coc.utils.is_valid_tag(tempTag):
AttributeError: partially initialized module 'coc' has no attribute 'utils' (most likely due to a circular import)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1310, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 883, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 876, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'clashlogin' raised an exception: AttributeError: partially initialized module 'coc' has no attribute 'utils' (most likely due to a circular import)

Issue:

Trying to initialize the package coc utils with

from coc import utils

Reason: I had created another python script called "coc.py" which overlapped with the coc package (circular import)

Solution: Delete or rename the script you made called coc.py

SouthernCure commented 2 months ago

Was totally an idiot, mb

doluk commented 2 months ago

could you please just add what the problem was? Just in case somebody is finding it and doesn't figure it out on their own.😊

Anubhav1603 commented 2 months ago

@SouthernCure have you named your file coc? ,because your error says circular imports

SouthernCure commented 2 months ago

Issue explained I am using a package called coc while also having another python script called coc.py to store functions. It was messing everything up, LOL; I'm creating a basic discord bot, which is on my GitHub if anyone needs some reference.

Anubhav1603 commented 2 months ago

Issue explained I am using a package called coc while also having another python script called coc.py to store functions. It was messing everything up, LOL; I'm creating a basic discord bot, which is on my GitHub if anyone needs some reference.

If you using coc.py then you cannot name your file coc instead name something else like main.py or something and try again to run your script

SouthernCure commented 2 months ago

Yeah, I already have a main.py and was going to save functions for Clash of Clans is coc.py; it's no big deal; I plan to redo it and give it another name anyways. Ill make sure there's no overlap

Also thanks for being so quick to respond didn't expect anyone even to see my issue within a day or two LOL