pythonquart

Quart error: "ImportError: cannot import name 'Headers' from 'h11._headers'"


I want to start a dashboard for my nextcord bot.

But when I imported my dashboard module with the line

import quart

it raises an error.

I did not find any other posts about this.

Error/Traceback

Traceback (most recent call last):
  File "main.py", line 1134, in <module>
    import dashboard
  File "/home/runner/tinoy/dashboard.py", line 7, in <module>
    import quart
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/quart/__init__.py", line 7, in <module>
    from .app import Quart
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/quart/app.py", line 38, in <module>
    from hypercorn.asyncio import serve
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/asyncio/__init__.py", line 6, in <module>
    from .run import worker_serve
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/asyncio/run.py", line 16, in <module>
    from .tcp_server import TCPServer
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/asyncio/tcp_server.py", line 11, in <module>
    from ..protocol import ProtocolWrapper
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/protocol/__init__.py", line 5, in <module>
    from .h2 import H2Protocol
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/protocol/h2.py", line 22, in <module>
    from .ws_stream import WSStream
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/hypercorn/protocol/ws_stream.py", line 9, in <module>
    from wsproto.connection import Connection, ConnectionState, ConnectionType
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/wsproto/__init__.py", line 9, in <module>
    from .connection import Connection, ConnectionState, ConnectionType
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/wsproto/connection.py", line 23, in <module>
    from .utilities import LocalProtocolError
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/wsproto/utilities.py", line 12, in <module>
    from h11._headers import Headers as H11Headers
ImportError: cannot import name 'Headers' from 'h11._headers' (/opt/virtualenvs/python3/lib/python3.8/site-packages/h11/_headers.py)

main.py

#. . .

if __name__ == "__main__":
    bot.version = "0.1.1"
    bot.ipc.start()
    dashboard.run(bot)
    bot.run(Token,reconnect=True)

dashboard.py


import os
import nextcord
import dotenv
import logging
import json
from func import readjson
import quart
from quart import redirect,url_for,render_template,request
from multiprocessing import Process
from quart_discord import DiscordOAuth2Session,Unauthorized,requires_authorization
from nextcord.ext import ipc
import asyncio
from threading import Thread
import aiosqlite


dotenv.load_dotenv()

ipc_client = bot.ipc_client
app = quart.Quart(__name__)
app.secret_key = os.getenv("quart_secret")
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"

app.config["DISCORD_CLIENT_ID"] = os.getenv("client_id")
app.config["DISCORD_CLIENT_SECRET"] = os.getenv("client_secret")
app.config["DISCORD_REDIRECT_URI"] =os.getenv("redirect_url")
app.config["DISCORD_BOT_TOKEN"] = os.getenv("Token")

discord = DiscordOAuth2Session(app)

#. . .
#Some routes…


def run(bot):
    bot.loop.create_task(app.run_task(host="0.0.0.0",port=8080))

I’m running on

Does anyone how to solve this?


Solution

  • I've resolved it by deleting the h11 and h11-0.13.0.dist-info folders in my Python environment (for you this seems like the directory is /opt/virtualenvs/python3/lib/python3.8/site-packages/) and just running pip install quart again afterwards.