python 运行错误收集
global全局声明错误
SyntaxError: name 'is_login' is used prior to global declaration
解决办法:global is_login 放在 if is_login:的上面
is_login = False
def login_auth(func_name):
def inner(*args, **kwargs):
if is_login:
res = func_name(*args, **kwargs)
return res
username = input('username>>>:').strip()
password = input('password>>>>:').strip()
if username == 'jason' and password =='123':
# 将全局名称空间中记录用户登录状态的数据值改为True
global is_login # 声明报错,需要写在函数定义的下面,即if is_login:上面
is_login = True
res = func_name(*args, **kwargs)
return res
else:
print('用户名或密码错误 无法执行函数')
return inner
字典使用不规范
func_dict = {
'1':register,
'2':login,
'3':add_shop_car,
'4':pay_shop_car
}
while True:
print("""
1.注册
2.登录
3.添加购物车
4.结算购物车
""")
choice = input('请输入功能编号>>>>:').strip()
if choice in func_dict:
func_name = func_dict(choice) ##错误
func_name()
else:
print('请输入正确编号')
应该使用如下:
func_name= func_dict[choice]或者用func_dict.get(choice)
使用requests请求https相关网站报错,可能使用了特殊代理配置导致的,解决方案是关闭代理即可
windows电脑pip安装mysqlclient报错
报错信息如下:
D:\Python38\Scripts>pip3.8 install pip_search
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))': /simple/pip-search/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))': /simple/pip-search/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))': /simple/pip-search/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))': /simple/pip-search/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))': /simple/pip-search/
Could not fetch URL https://pypi.org/simple/pip-search/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip-search/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1124)'))) - skipping
ERROR: Could not find a version that satisfies the requirement pip_search (from versions: none)
ERROR: No matching distribution found for pip_search
解决方案:电脑开了代理,关闭代理就解决了。通过谷歌搜索如下:
windows pip 安装报错 No matching distribution found
django数据库迁移失败:
更换数据库和项目即可
问题:报数据类型没有对应对象:'NoneType' object has no attribute 'username'
解决方法:打印这个对象是否为空,如果对象是none,就没有任何属性和方法。更换判断条件即可。