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 一些错误处理的更多相关文章

  1. Python2.7错误处理FileNotFoundError报错NameError: name 'FileNotFoundError' is not defined

    错误信息如下: 原因是FileNotFoundError是python3.0中的写法,而Python2.7中应写为IOError.

  2. python抓取bing主页背景图片

    最初Python2写法: #!/usr/bin/env python # -*- coding:utf-8 -*- # -*- author:nancy -*- # python2抓取bing主页所有 ...

  3. Leetcode刷题python

    Two Sum 两数==target 方法二更好 题1,对时间复杂度有要求O(n),所以维护一个字典,遍历过的数值放在字典中,直接遍历时候查找字典中有没有出现差,查找字典时间复杂度是O(1),所以O( ...

  4. centos下安装opencv

    根据项目需要,安装opencv并提供给开发使用,并且使用opencv提供python3的API接口.虽然不知道是个啥,还是简单了解下. opencv是什么? OpenCV的全称是Open Source ...

  5. 航空概论(历年资料,引之百度文库,PS:未调格式,有点乱)

    航空航天尔雅 选择题1. 已经实现了<天方夜谭>中的飞毯设想.—— A——美国2. 地球到月球大约—— C 38 万公里3. 建立了航空史上第一条定期空中路线—— B——德国4. 对于孔明 ...

  6. 解决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进行网络爬虫时,最头疼的就是转码问题,下面是 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [svc]caffe安装笔记-显卡购买

    caffe,这是是数据组需要做一些大数据模型的训练(深度学习), 要求 服务器+显卡(运算卡), 刚开始老板让买的牌子是泰坦的(这是2年前的事情了). 后来买不到这个牌子的,(jd,tb)看过丽台的, ...

  2. phpcms v9实现调用多个栏目id的方法

    {pc:content action="position" posid="14" catid="13,14,15,16,17,18,19,20,21& ...

  3. [转]wordpress安装插件的3种方式

    WordPress插件安装方法有几种?WordPress是一种使用PHP语言开发的博客平台,有些用户不知道怎么安装WordPress插件和主题的,所以今天小编就为大家介绍几种WordPress插件安装 ...

  4. ES查看配置和查看全部配置

    http://10.0.0.17:9200/blog/_settings   GET 获取单个index(库的配置) http://10.0.0.17:9200/_settings/_all   GE ...

  5. CI框架中 日志输出方法log_message()只允许输出字符串解决方案

    1.修改CodeIgniter/index.php,添加如下: define('ROOTDIR',dirname(__FILE__).'/'); 2.修改CodeIgniter/application ...

  6. 圆角带箭头的提示框css实现

    css是一个很强大的东西,很多网页效果,我们可以通过css直接实现.今天给大家分享的是一个用css实现的圆角带箭头的提示框. 效果如下图: 这一个样式主要涉及到了css的边框样式border的运用和定 ...

  7. Easyui Datagrid的Rownumber行号显示问题

    Datagrid中当你的行数据超过9999时,第一列的行号rownumber将会因为表格内容过长而导致无法显示全部数字, 这一点Easyui无法做到自适应 所以需要进行修改,这里扩展一个方法就行了. ...

  8. Oracle启动中,spfile.ora、init<SID>.ora、spfile<SID>.ora 这三个文件正确的先后顺序是什么?

    Oracle启动中,spfile.ora.init<SID>.ora.spfile<SID>.ora 这三个文件正确的先后顺序是什么? 解答:启动数据库,使用startup命令 ...

  9. 嵌入式驱动开发之dsp 算法优化vlib emcv---算法优化

    http://www.opencv.org.cn/forum.php?mod=forumdisplay&fid=9

  10. 开发人员需知的Web缓存知识(转)

    什么是Web缓存,为什么要使用它? 缓存的类型: 浏览器缓存: 代理服务器缓存: 网关缓存: Web缓存无害吗?为什么要鼓励缓存? Web缓存如何工作 如何控制缓存和不缓存: HTML Meta标签 ...