Python-学习笔记之错误搜集(一)

1.错误描述:heroku local web 出现错误Connection in use: ('0.0.0.0', 5000)...

(ll_env) ZFJ:LearningLog zfj$ heroku local
10:07:30 web.1   |  [2018-09-26 10:07:30 +0800] [3743] [INFO] Starting gunicorn 19.9.0
10:07:30 web.1   |  [2018-09-26 10:07:30 +0800] [3743] [ERROR] Connection in use: ('0.0.0.0', 5000)
10:07:30 web.1   |  [2018-09-26 10:07:30 +0800] [3743] [ERROR] Retrying in 1 second.
10:07:31 web.1   |  [2018-09-26 10:07:31 +0800] [3743] [ERROR] Connection in use: ('0.0.0.0', 5000)
10:07:31 web.1   |  [2018-09-26 10:07:31 +0800] [3743] [ERROR] Retrying in 1 second.
10:07:32 web.1   |  [2018-09-26 10:07:32 +0800] [3743] [ERROR] Connection in use: ('0.0.0.0', 5000)
10:07:32 web.1   |  [2018-09-26 10:07:32 +0800] [3743] [ERROR] Retrying in 1 second.
10:07:33 web.1   |  [2018-09-26 10:07:33 +0800] [3743] [ERROR] Connection in use: ('0.0.0.0', 5000)
10:07:33 web.1   |  [2018-09-26 10:07:33 +0800] [3743] [ERROR] Retrying in 1 second.
10:07:34 web.1   |  [2018-09-26 10:07:34 +0800] [3743] [ERROR] Connection in use: ('0.0.0.0', 5000)
10:07:34 web.1   |  [2018-09-26 10:07:34 +0800] [3743] [ERROR] Retrying in 1 second.
10:07:35 web.1   |  [2018-09-26 10:07:35 +0800] [3743] [ERROR] Can't connect to ('0.0.0.0', 5000)
[DONE] Killing all processes with signal  SIGINT
10:07:35 web.1   Exited with exit code null

解决办法: kill `lsof -i :5000`

(ll_env) ZFJ:LearningLog zfj$ kill `lsof -i :5000`
-bash: kill: COMMAND: arguments must be process or job IDs
-bash: kill: PID: arguments must be process or job IDs
-bash: kill: USER: arguments must be process or job IDs
-bash: kill: FD: arguments must be process or job IDs
-bash: kill: TYPE: arguments must be process or job IDs
-bash: kill: DEVICE: arguments must be process or job IDs
-bash: kill: SIZE/OFF: arguments must be process or job IDs
-bash: kill: NODE: arguments must be process or job IDs
-bash: kill: NAME: arguments must be process or job IDs
-bash: kill: AirServer: arguments must be process or job IDs
-bash: kill: zfj: arguments must be process or job IDs
-bash: kill: 11u: arguments must be process or job IDs
-bash: kill: IPv4: arguments must be process or job IDs
-bash: kill: 0x2e00b17d95b871cf: arguments must be process or job IDs
-bash: kill: 0t0: arguments must be process or job IDs
-bash: kill: TCP: arguments must be process or job IDs
-bash: kill: *:commplex-main: arguments must be process or job IDs
-bash: kill: (LISTEN): arguments must be process or job IDs
-bash: kill: AirServer: arguments must be process or job IDs
-bash: kill: zfj: arguments must be process or job IDs
-bash: kill: 12u: arguments must be process or job IDs
-bash: kill: IPv6: arguments must be process or job IDs
-bash: kill: 0x2e00b17d813922bf: arguments must be process or job IDs
-bash: kill: 0t0: arguments must be process or job IDs
-bash: kill: TCP: arguments must be process or job IDs
-bash: kill: *:commplex-main: arguments must be process or job IDs
-bash: kill: (LISTEN): arguments must be process or job IDs

2.错误描述:'block' tag with name 'content' appears more than once

因为block content在html文本中出现多次,block content即使是被注释了也不行;删除注释的block content部分就OK了。

3.错误描述:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)

这是因为ascii编码的问题,导入gb18030就OK了

import sys
reload(sys)
sys.setdefaultencoding(‘gb18030')

4.错误描述:name 'FileNotFoundError' is not defined

FileNotFoundError是Python3文本不存在的异常处理方法,在Python3.0以下的版本使用IOError。

5.错误描述:SyntaxError: Non-ASCII character '\xe5' in file *******

这是因为Python的默认编码文件用的是ASCII,将文件转为UTF-8,直接在头文件导入以下代码就行;

# -*- coding: UTF-8 -*-    或者  #coding=utf-8
注意:这句代码一定要添加在源码的第一行;

6.在终端Python2.7上使用input的时候,输入的内容要使用引号括起来,但是使用raw_input不用;

7.错误描述:Invalid HTTP_HOST header: ‘xxx.xxx.x.xxx:5000'. You may need to add u’xxx.xxx.x.xxx’ to ALLOWED_HOSTS.

修改项目的配置文件settings.py中的ALLOWED_HOSTS项;

原代码:ALLOWED_HOSTS = []

可以在ALLOWED_HOSTS中添加你的请求地址,如下:

ALLOWED_HOSTS = ['192.168.1.103', 'localhost', '0.0.0.0']

也可以这样写:

ALLOWED_HOSTS = ['*']

最后一种是让项目支持所有的主机头,方便部署。

8.urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)>

问题描述:在使用urllib进行网络请求的时候,会有上面?的错误❌,代码如下:

import urllib.request

response = urllib.request.urlopen('https://www.python.org')

print(response.read())

结果如下:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File 
......省略了......
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)>
[Finished in 0.7s with exit code 1]
[cmd: ['/Library/Frameworks/Python.framework/Versions/3.7/bin/python3', '-u', '/Users/zhangfujie/Desktop/urllib_study.py']]
[dir: /Users/zhangfujie/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

解决办法:

a.使用ssl创建未经验证的上下文,在urlopen中传入上下文参数

import ssl

import urllib.request

context = ssl._create_unverified_context()

response = urllib.request.urlopen('https://www.python.org', context=context)

print(response.read())

b.全局取消证书验证

import ssl

import urllib.request

ssl._create_default_https_context = ssl._create_unverified_context

response = urllib.request.urlopen('https://www.python.org')

print(response.read())

 

 

============未完待续============

 

 

结束语

欢迎各位大神补充!

欢迎大家加移动开发技术交流群,在这里大家可以一起讨论学习,这里有大佬,也有小菜鸟,没事还能斗斗图装装逼,如果需要换工作的还能相互推荐,期待大家的加入!

 

 

©️2020 CSDN 皮肤主题: 成长之路 设计师: Amelia_0503 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值