Python Errors and Solutions

The Python Errors section of the website attempts to provide solutions for common and frustrating python errors encountered during development.

pyyaml AttributeError: cython_sources

The Issue The problem was first reported on the PyYAML GitHub repository, under the issue titled AttributeError: ‘CythonSources’ with Cython 3.0.0a10. Users reported that when trying to install PyYAML from sources with Cython 3.0.0a10, the installation failed and threw an AttributeError: ‘CythonSources’. This issue was widely discussed, and several solutions were proposed by the community. In this blog post, we will go over these proposed solutions to help you navigate this compatibility issue.

Scapy_Exception: No /dev/bpf handle is available !

This error is encountered when scapy trys to send packets and does not have permission. console> python scapy-script Scapy_Exception: No /dev/bpf handle is available ! console> Workaround scapy related commands should be ran with sudo. console> sudo python scapy-script 1 Packet Sent console>

Python Standard Library Built-In Exceptions

Class hierarchy of built-in exceptions BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception +-- StopIteration +-- StopAsyncIteration +-- ArithmeticError | +-- FloatingPointError | +-- OverflowError | +-- ZeroDivisionError +-- AssertionError +-- AttributeError +-- BufferError +-- EOFError +-- ImportError | +-- ModuleNotFoundError +-- LookupError | +-- IndexError | +-- KeyError +-- MemoryError +-- NameError | +-- UnboundLocalError +-- OSError | +-- BlockingIOError | +-- ChildProcessError | +-- ConnectionError | | +-- BrokenPipeError | | +-- ConnectionAbortedError | | +-- ConnectionRefusedError | | +-- ConnectionResetError | +-- FileExistsError | +-- FileNotFoundError | +-- InterruptedError | +-- IsADirectoryError | +-- NotADirectoryError | +-- PermissionError | +-- ProcessLookupError | +-- TimeoutError +-- ReferenceError +-- RuntimeError | +-- NotImplementedError | +-- RecursionError +-- SyntaxError | +-- IndentationError | +-- TabError +-- SystemError +-- TypeError +-- ValueError | +-- UnicodeError | +-- UnicodeDecodeError | +-- UnicodeEncodeError | +-- UnicodeTranslateError +-- Warning +-- DeprecationWarning +-- PendingDeprecationWarning +-- RuntimeWarning +-- SyntaxWarning +-- UserWarning +-- FutureWarning +-- ImportWarning +-- UnicodeWarning +-- BytesWarning +-- ResourceWarning Reference Python Documenation: Built-in Exceptions

[pydantic] NameError: Field name "schema" shadows a BaseModel attribute; use a different field name with "alias='schema'".

This error is encountered when you define a pydantic class that has a attributed named schema. class EmbedDoc(BaseModel): schema: int = 1 name: str = Field(str) tags: List[str] archived: bool The schema attribute is special field for pydantic……. Workaround You can specify a field alias and when the document is serialized it will use the field name schama instead of schema_. class EmbedDoc(BaseModel): schema_: int = Field(1, alias="schema") name: str = Field(str) tags: List[str] archived: bool

ValueError: Cannot specify ',' with 's'.

Problem This error is raised when you pass a string to the format() function The ValueError exception occurs when you attempt to pass a variable of type string to format(). >>> pop="4534305483" >>> type(pop) <class 'str'> >>> print(format(pop,",")) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: Cannot specify ',' with 's'. >>> Solution The format() function can be used to format a long number with commas

django.core.exceptions

This page cotains a list of possible Exception raised by the Django Web Framework. FieldDoesNotExist Inherits from Exception Description: “The requested model field does not exist” AppRegistryNotReady Inherits from Exception Description: “The django.apps registry is not populated yet” ObjectDoesNotExist Inherits from Exception Description: “The requested object does not exist”, MultipleObjectsReturned Inherits from Exception Description: “The query returned multiple objects when only one was expected.” SuspiciousOperation Inherits from Exception Description: “The user did something suspicious”

error: invalid command 'egg_info'

This error is encountered when running pip install Distribute has been merged into Setuptools as of version 0.7. If you are using a version <=0.6, upgrade using pip install --upgrade setuptools or easy_install -U setuptools. Reference: https://stackoverflow.com/questions/11425106/python-pip-install-fails-invalid-command-egg-info