gpt4 book ai didi

python 文件显示 AttributeError : module 'http' has no attribute 'client'

转载 作者:太空狗 更新时间:2023-10-29 20:29:46 25 4
gpt4 key购买 nike

我有以下 Python 脚本:

import http
import requests
from bs4 import BeautifulSoup
import urllib3
import pyrebase
import numpy as np
import yagmail
import time
from datetime import datetime, timedelta
import sys
import logging
import colorama
import csv
from random import randint
from numpy import genfromtxt
import sched, time
import threading
import http.client

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db


# Fetch the service account key JSON file contents
cred = credentials.Certificate('service-account-credentials.json')
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://werrwrrw-catalogue.firebaseio.com'
})


config = {
"apiKey": "BiXzaSdwhjwrhwjjrhwr",
"authDomain": "whjwrhwjjrhwr.firebaseapp.com",
"databaseURL": "https://whjwrhwjjrhwr.firebaseio.com",
"projectId": "whjwrhwjjrhwr",
"storageBucket": "rewrrrrr.appspot.com",
"messagingSenderId": "606543434441"
}



firebaseuser = pyrebase.initialize_app(config)

auth = firebaseuser.auth()
dbuser = firebaseuser.database()

subref = db.reference('Subcribers').get()

for key, val in subref.items():
subcriber_email = val['Email']
print(key,subcriber_email)

python 文件之前运行良好,但现在当我尝试运行它时,它显示以下错误:

>>Traceback (most recent call last):
  File "fax.py", line 1, in <module>
    import requests
  File "/Users/name/anaconda/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/Users/name/anaconda/lib/python3.6/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/Users/name/anaconda/lib/python3.6/http/client.py", line 71, in <module>
    import email.parser
  File "/Users/name/Desktop/Google Drive/FEBB/serverless/crwlr/email.py", line 3, in <module>
    from bs4 import BeautifulSoup
  File "/Users/name/anaconda/lib/python3.6/site-packages/bs4/__init__.py", line 35, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/Users/name/anaconda/lib/python3.6/site-packages/bs4/builder/__init__.py", line 323, in <module>
    from . import _html5lib
  File "/Users/name/anaconda/lib/python3.6/site-packages/bs4/builder/_html5lib.py", line 20, in <module>
    import html5lib
  File "/Users/name/anaconda/lib/python3.6/site-packages/html5lib/__init__.py", line 19, in <module>
    from .serializer import serialize
  File "/Users/name/anaconda/lib/python3.6/site-packages/html5lib/serializer/__init__.py", line 5, in <module>
    from .htmlserializer import HTMLSerializer
  File "/Users/name/anaconda/lib/python3.6/site-packages/html5lib/serializer/htmlserializer.py", line 15, in <module>
    from xml.sax.saxutils import escape
  File "/Users/name/anaconda/lib/python3.6/xml/sax/saxutils.py", line 6, in <module>
    import os, urllib.parse, urllib.request
  File "/Users/name/anaconda/lib/python3.6/urllib/request.py", line 1350, in <module>
    if hasattr(http.client, 'HTTPSConnection'):
AttributeError: module 'http' has no attribute 'client'

我无法真正查明错误。如何阅读基于上述回溯的修复错误?

最佳答案

这里:

File "/Users/name/anaconda/lib/python3.6/http/client.py", line 71, in <module>
import email.parser
File "/Users/name/Desktop/Google Drive/FEBB/serverless/crwlr/email.py"
from bs4 import BeautifulSoup

/Users/name/Desktop/Google Drive/FEBB/serverless/crwlr/中的本地 email.py 隐藏了 stdlib 的那个。现在在您的本地 email.py 模块中,您正在导入 bs4,它导入 html5lib,它导入 xml.sax.saxutils,它导入 urllib.request,它想要导入 http

IOW 你最终得到了一个(意外的)循环依赖。此时 http 模块只是部分导入,还没有定义“客户端”,因此出现错误。

简单的解决方案是将“email.py”模块重命名为其他名称,或者(如果它只是一个脚本而不是模块)将其移出 pythonpath。

编辑:我刚刚注意到您的代码是通过导入 http 开始的,因此 http 模块 应该 已经完全加载,所以即使您的 有问题email.py 脚本/模块需要修复,这不应该导致这个问题。因此,您的 sys.path 中很可能有另一个 http.py 模块或 http 包遮蔽了 stdlib 的模块。要对此进行调试,请在 import http 之后添加此行:

 print(http)

这应该打印出如下内容:

<module 'http' from '/some/path/to/a/python/file.pyc`>

如果路径不是您的 python 安装 stdlib 的“http/init.pyc”路径,那么您就找到了违规者。如果它是您自己的脚本/模块之一,修复方法与 email.py 相同。

关于python 文件显示 AttributeError : module 'http' has no attribute 'client' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51963760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com