File "C:\Users\Dell\PycharmProjects\pythonProject2\venv\ex.8.3.py", line 10, in find path=join(now,subPath) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ntpath.py", line 116, in join result_drive, result_path = splitdrive(path) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ntpath.py", line 169, in splitdrive p = os.fspath(p) RecursionError: maximum recursion depth exceeded while calling a Python object
时间: 2023-06-12 20:06:48 浏览: 207
这个错误是递归深度超过了Python的最大递归深度所导致的。这通常是因为代码中存在无限递归的情况,导致程序无限循环调用自身,直到递归深度达到Python的最大限制。您可以尝试增加Python的最大递归深度来解决这个问题,但这并不是一个好的解决方案,因为它只是掩盖了底层问题。相反,您应该检查您的代码并找出递归无限循环的原因,并修复它。
相关问题
出现了错误C:\Users\28269\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\28269\PycharmProjects\pythonProject\venv\ojhj.py Traceback (most recent call last): File "C:\Users\28269\PycharmProjects\pythonProject\venv\ojhj.py", line 26, in <module> trs = table.find_all("tr") AttributeError: 'NoneType' object has no attribute 'find_all'
这个错误是因为在代码中,定位 `table` 标签时没有成功找到表格,导致 `table` 变量是 `NoneType` 类型,而 `NoneType` 类型是没有 `find_all` 方法的,所以报错了。
这个问题可以通过检查网页源码,确定是否定位的标签名和 class 名是否正确。在这个网站上,可以发现目标表格的 class 名为 `table-striped`,所以需要修改代码中的定位方式。
以下是修改后的代码:
```
import requests
from bs4 import BeautifulSoup
import pandas as pd
#定义链接
url="https://www.yoojia.com/rank/1-0-0-0-0-0.ht"
#定义请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'
}
#获取网页源码
html = requests.get(url=url,headers=headers)
#将网页源码装换为txt
main_page = html.text
#使用bs4对网页源码进行解析
main_page = BeautifulSoup(main_page,"html.parser")
#定位table
table = main_page.find("table", attrs={"class": "table-striped"})
#检查是否成功找到了表格
if table is None:
print("没有找到表格")
else:
#获取所有table里头的tr标签
trs = table.find_all("tr")
#定义数据容器
data = []
#遍历所有 tr标签
for i in trs[1:]:
#定义零时容器
list = []
#定位tr里头的所有td标签
tds = i.find_all("td")
#遍历所有td标签
for td in tds:
#将td里头的文本添加到零时容器
list.append(td.text.strip())
#将零时容器内的数据添加值data里头
data.append(list)
#定义储存标题
columns=["排名","品牌","车型","销量","市场占有率","同比增长"]
#使用pandas 储存
#定义个dataframe
df = pd.DataFrame(columns=columns, data=data)
#使用csv格式储存
df.to_csv("./Data.csv", encoding='utf-8', index=False)
#保存完毕
print("保存完毕")
```
请注意,如果仍然无法找到表格,可能是网站的页面结构发生了变化,需要重新检查定位方式。
报错C:\Users\Administrator\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/main.py Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 3, in <module> conn = pymysql.connect(host='localhost', user='root', password='password') File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 352, in __init__ self.connect() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 636, in connect self._request_authentication() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 911, in _request_authentication auth_packet = self._read_packet() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 729, in _read_packet packet.raise_for_error() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error err.raise_mysql_exception(self._data) File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
这个错误提示是因为连接MySQL数据库时,用户名或密码不正确,你需要检查一下你的用户名和密码是否正确。同时,也需要确保你的MySQL服务器已经启动,并且允许远程连接。
如果你忘记了MySQL的用户名和密码,可以尝试使用以下命令来重置密码:
1. 停止MySQL服务
```
sudo service mysql stop
```
2. 以跳过授权方式启动MySQL
```
sudo mysqld_safe --skip-grant-tables --skip-networking &
```
3. 使用root用户登录MySQL
```
mysql -u root
```
4. 切换到mysql数据库
```
use mysql;
```
5. 更新root用户的密码
```
update user set authentication_string=password('your_new_password') where user='root' and Host ='localhost';
```
6. 刷新权限
```
flush privileges;
```
7. 退出MySQL并重新启动服务
```
exit;
sudo service mysql start
```
然后,你可以使用新的密码来连接你的MySQL数据库了。
阅读全文