python2 一些错误处理
python2各种问题
pip安装django出错:python2 -m pip install django
编码问题:Unicode Decode Error ascii codec can't decode byte...
原因:windows系统默认编码是gbk,而pip默认编码是utf8,故出错
解决方法: python27\Lib\site-packages下,新建一个 sitecustomize.py 文件,写入
import sys
sys.setdefaultencoding('gbk')
pip安装django出错:python2 -m pip install django
源码编译问题:IOError: [Errno 22] invalid mode ('wb') or filename
原因:pip默认下载最新版本,最新版本为django2.0,而源上只有django2.0 python3的whl文件,没有python2的whl文件。因此只能采用源码编译安装,而源码编译安装又出了这个错误
解决方法:指定下载较低版本的django,这里用django 1.11.4
查看django版本:https://pypi.python.org/pypi
pip指定版本号用“==”:
python2 -m pip install django==1.11.4
启动django出错:python2 manage.py runserver
RuntimeError: maximum recursion depth exceeded in cmp
django启动时出错,报错显示在python27/Lib/functool.py的第56行
解决办法:在python目录中的Lib下面找到functools将56行
convert = {
'__lt__': [('__gt__', lambda self, other: other < self),
('__le__', lambda self, other: not other < self),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: other <= self),
('__lt__', lambda self, other: not other <= self),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: other > self),
('__ge__', lambda self, other: not other > self),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: other >= self),
('__gt__', lambda self, other: not other >= self),
('__lt__', lambda self, other: not self >= other)]
}
修改成:
convert = {
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
('__le__', lambda self, other: self < other or self == other),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
('__lt__', lambda self, other: self <= other and not self == other),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
('__ge__', lambda self, other: self > other or self == other),
('__le__', lambda self, other: not self > other)],
'__ge__ ': [('__le__', lambda self, other: (not self >= other) or self == other),
('__gt__', lambda self, other: self >= other and not self == other),
('__lt__', lambda self, other: not self >= other)]
}
django连接postgresql出错:python2 manage.py runserver
django.db.utils.OperationalError:
FATAL: no pg_hba.conf entry for host "172.16.23.129", user "postgres", database "datamanager", SSL on
FATAL: no pg_hba.conf entry for host "172.16.23.129", user "postgres", database "datamanager", SSL off
PostgreSQ数据库为了安全,它不会监听除本地以外的所有连接请求,当用户通过JDBC访问是,会报一些如下的异常:
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host
要解决这个问题,只需要在PostgreSQL数据库的安装目录下找到/data/pg_hba.conf,找到“# IPv4 local connections:”
在其下加上请求连接的机器IP
host all all 127.0.0.1/32 md5
32是子网掩码的网段;md5是密码验证方法,可以改(见文件pg_hba.conf上的说明)
python2 一些错误处理的更多相关文章
- Python2.7错误处理FileNotFoundError报错NameError: name 'FileNotFoundError' is not defined
错误信息如下: 原因是FileNotFoundError是python3.0中的写法,而Python2.7中应写为IOError.
- python抓取bing主页背景图片
最初Python2写法: #!/usr/bin/env python # -*- coding:utf-8 -*- # -*- author:nancy -*- # python2抓取bing主页所有 ...
- Leetcode刷题python
Two Sum 两数==target 方法二更好 题1,对时间复杂度有要求O(n),所以维护一个字典,遍历过的数值放在字典中,直接遍历时候查找字典中有没有出现差,查找字典时间复杂度是O(1),所以O( ...
- centos下安装opencv
根据项目需要,安装opencv并提供给开发使用,并且使用opencv提供python3的API接口.虽然不知道是个啥,还是简单了解下. opencv是什么? OpenCV的全称是Open Source ...
- 航空概论(历年资料,引之百度文库,PS:未调格式,有点乱)
航空航天尔雅 选择题1. 已经实现了<天方夜谭>中的飞毯设想.—— A——美国2. 地球到月球大约—— C 38 万公里3. 建立了航空史上第一条定期空中路线—— B——德国4. 对于孔明 ...
- 解决Python2.7的UnicodeEncodeError:'ascii' codec can't encode characters in position 0-78: ordinal not in range(128)异常错误
解决Python2.7的UnicodeEncodeError: 'ascii' codec can't encode异常错误 大家都知道,在使用python进行网络爬虫时,最头疼的就是转码问题,下面是 ...
- CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误
安装如下方法安装python2.7: yum install –y python27 python27-devel python-docutils cd /usr/bin/ rm -rf python ...
- centos 安装python3与Python2并存,并解决"smtplib" object has no attribute 'SMTP_SSL'的错误
1.需要先安装python3依赖的包yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readli ...
- Python2 错误记录1File "<string>", line 1, in <module> NameError: name 'f' is not defined
Python 2下 count = 0 while count < 3: user = input('>>>') pwd = input('>>>') if ...
随机推荐
- FPGA学习(第8节)-Verilog设计电路的时序要点及时序仿真
一个电路能跑到多少M的时钟呢? 这和电路的设计有密切联系(组合逻辑的延时),我们知道电路器件都是由一定延迟的,所以信号的仿真很重要.如果延迟时间大于时钟,就会导致时序违例,出现逻辑错误. 项目要求30 ...
- tail 命令详解
tail 指令 功能:从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不 ...
- Ubuntu 14.04 下FTP服务器的搭建
FTP服务器的搭建,我要实现的需求是: 不允许匿名访问,因为我的机器不想让谁都能登录上来,随便获取文件, 需要锁定一个目录,因为在家里,我需要给媳妇下载一些电影 韩剧之类的东西,媳妇会来我机器下载,但 ...
- Github 创建新分支
一.clone Repository clone Github 上的Repository,如下: git clone git@github.com:FBing/design-patterns.git ...
- lseek,fcntl,ioctl函数
函数说明:每一个已打开的文件都有一个读写位置, 当打开文件时通常其读写位置是指向文件开头, 若是以附加的方式打开文件(如O_APPEND), 则读写位置会指向文件尾. 当read()或write()时 ...
- 如何有效地提升JavaScript 水平?
lyuehh 努力学习中.. 9 人赞同 简单的介绍一下, 不一定准确, 大家一起进步... (单词大小写什么的别计较....) 学习js主要是一下几个方面, js语言本身的知识, 和浏览器相关的知识 ...
- python学习笔记3---浅拷贝和深拷贝,file操作
import copy a=[1,2,3,['a','b']] b=a c= copy.copy(a)---浅拷贝 d=copy.deepcopy(a)---深拷贝 file操作: python 文件 ...
- C++ 抽象类二(抽象类的基本语法)
//抽象类的基本语法 #include<iostream> using namespace std; /* 有关多继承的说明 被实际开发经验抛弃的多继承 工程开发中真正意义上的多继承是几乎 ...
- js 自定义类
将近20年前,Javascript诞生的时候,只是一种简单的网页脚本语言.如果你忘了填写用户名,它就跳出一个警告. 如今,它变得几乎无所不能,从前端到后端,有着各种匪夷所思的用途.程序员用它完成越来越 ...
- java三大框架SSH(Struts2 Spring Hibernate)
http://www.cnblogs.com/qiuzhongyang/p/3874149.html