#####20181225

1.
python解决SNIMissingWarning和InsecurePlatformWarning警告
在想要获取https站点的资源时,会报出SNIMissingWarning和InsecurePlatformWarning警告

SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform.

This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning

解决方法:

在cmd中输入:
pip install pyopenssl ndg-httpsclient pyasn1

2.在安装python的pip工具时,遇到以下报错[Errno -3] Temporary failure

https://www.aliyun.com/jiaocheng/519493.html
以上问题发现原来是DNS配置错误,域名服务器地址是本机IP地址,127.0.0.1,所以修改域名服务器

sudo gedit /etc/resolv.conf

nameserver 8.8.8.8

3.

/usr/local/lib/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.

解决方法
1.pip2.7 install cryptography==2.7

Collecting cryptography==2.7
Could not find a version that satisfies the requirement cryptography==2.7 (from versions: 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.8.2, 0.9, 0.9.1, 0.9.2, 0.9.3, 1.0, 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2, 2.2.1, 2.2.2, 2.3, 2.3.1, 2.4, 2.4.1, 2.4.2)
No matching distribution found for cryptography==2.7

2.
or upgrade python2.7.(new)

3.use pyenv
(使用 pyenv,cache 目录下存放,手工切换,install安装python)
http://blog.51cto.com/9940459/1868533

pip常用命令
列出安装的packages:pip freeze

$ pip install --egg pyenv

pip install pyenv

NOTE: pip freeze will not show pyenv as installed as this tool is just a thin wrapper around the shell install script.

step 安装pyenv
https://github.com/pyenv/pyenv
choose 左上角 clone or download

##wget https://github.com/yyuu/pyenv/archive/v20160726.tar.gz

mv v20160726.tar.gz pyenv-20160726.tar.gz

##tar zxvf pyenv-20160726.tar.gz
unzip pyenv-master*

#######sed -i "s/https:\/\/www\.Python\.org\/ftp\/python/http:\/\/mirrors\.sohu\.com\/pytn/g" `grep https://www.python.org/ftp/python -rl pyenv-20160726/plugins/python-build/share/python-build/*`

sed -i "s/https:\/\/www\.Python\.org\/ftp\/python/http:\/\/mirrors\.sohu\.com\/pytn/g" `grep https://www.python.org/ftp/python -rl pyenv-master/plugins/python-build/share/python-build/*`

mv pyenv-master ~/.pyenv

#######mv pyenv-20160726 ~/.pyenv

export PATH=~/.pyenv/shims:~/.pyenv/bin:$PATH

pyenv install -l

vim ./bash_profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

卸载
mv ~/.pyenv pyenv-20160726

Uninstalling pyenv
The simplicity of pyenv makes it easy to temporarily disable it, or uninstall from the system.

To disable pyenv managing your Python versions, simply remove the pyenv init line from your shell startup configuration. This will remove pyenv shims directory from PATH, and future invocations like python will execute the system Python version, as before pyenv.
pyenv will still be accessible on the command line, but your Python apps won't be affected by version switching.

To completely uninstall pyenv, perform step (1) and then remove its root directory. This will delete all Python versions that were installed under $(pyenv root)/versions/ directory:

rm -rf $(pyenv root)
If you've installed pyenv using a package manager, as a final step perform the pyenv package removal. For instance, for Homebrew:

brew uninstall pyenv

#######
命令:

pyenv install -l 查看当前Pyenv支持的python版本。

pyenv install 3.5.2 安装3.5.2版本

pyenv local 3.5.2 切换本地目录下的python环境的版本号为3.5.2

pyenv local system 切换本地目录下的Python环境的版本号为系统默认。

pyenv virtualenv 3.5.2 linux 创建基于3.5.2 版本的虚拟环境

pyenv uninstall linux 删除虚拟环境。

#######

如果下载太慢可以自已下载添加到 http://mirrors.sohu.com/python/ 下载源

[root@client ~]# cd ~/.pyenv

[root@client .pyenv]# cp /root/Python-2.7.12.tar.xz cache/

[root@client .pyenv]# ls cache/

Python-2.7.12.tar.xz

[root@client .pyenv]# cd

[root@client ~]# pyenv install 2.7.12

**比如你创建 了 A 目录 并在里面pyenv local 2.7.12 (重要)

创建 了 B目录。 并在里面pyenv local 3.5.2

这样,你cd 进A目录,里面的python 就是2.7.12

cd进B目录,里面的python 就是3.5.2的

这样很方便的在各个版本之间切换。只要切换当前的目录就好

[root@pythontest .pyenv]# pyenv install 2.7.14
Installing Python-2.7.14...
Installed Python-2.7.14 to /root/.pyenv/versions/2.7.14

##########pip 通过pip命令导出(python3)和导入Python环境安装包(python2)

1.
pip2 freeze > packages.txt

2.
python -m pip install -r packages.txt
Downloading http://mirrors.aliyun.com/pypi/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99kB)
100% |████████████████████████████████| 102kB 3.8MB/s
Installing collected packages: asn1crypto, pycparser, cffi, six, bcrypt, configparser, enum34, idna, ipaddress, cryptography, cx-Oracle, pytz, Django, django-crontab, django-guardian, mysqlclient, PyNaCl, pyasn1, paramiko, pyExcelerator, xlrd, xlwt, xlutils
Running setup.py install for pycparser ... done
Running setup.py install for configparser ... done
Running setup.py install for django-crontab ... done
Running setup.py install for mysqlclient ... done
Running setup.py install for pyExcelerator ... done
Successfully installed Django-1.11.16 PyNaCl-1.3.0 asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.5 configparser-3.5.0 cryptography-2.3.1 cx-Oracle-7.0.0 django-crontab-0.7.1 django-guardian-1.4.9 enum34-1.1.6 idna-2.7 ipaddress-1.0.22 mysqlclient-1.3.13 paramiko-2.4.2 pyExcelerator-0.6.4.1 pyasn1-0.4.4 pycparser-2.19 pytz-2018.7 six-1.11.0 xlrd-1.1.0 xlutils-2.0.0 xlwt-1.3.0
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@pythontest ~]#

3.
python -m pip download -r packages.txt

4.
pip install /root/package/six-1.11.0-py2.py3-none-any.whl

or
执行方法:
1.使用setuptools工具安装xlrd模块
1) 安装setuptools工具
gunzip setuptools-2.0.tar.gz
tar -xvf setuptools-2.0.tar
python setup.py build
python setup.py install

2)安装xlrd模块
gunzip xlrd-1.1.0.tar.gz
tar -xvf xlrd-1.1.0.tar
python setup.py install

######################3

drwxr-xr-x. 4 root root 4096 12月 25 16:42 mysql_mon
[root@pythontest db_monitor-master]# python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7fe0a234ab90>
Traceback (most recent call last):
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
self.check(display_num_errors=True)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(**kwargs))
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/base.py", line 1284, in check
errors.extend(cls._check_fields(**kwargs))
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/base.py", line 1359, in _check_fields
errors.extend(field.check(**kwargs))
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 913, in check
errors = super(AutoField, self).check(**kwargs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 219, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 322, in _check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 49, in check_field
field_type = field.db_type(self.connection)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 644, in db_type
return connection.data_types[self.get_internal_type()] % data
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 174, in data_types
if self.features.supports_microsecond_precision:
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/mysql/features.py", line 53, in supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 385, in mysql_version
with self.temporary_connection() as cursor:
File "/root/.pyenv/versions/2.7.14/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 591, in temporary_connection
cursor = self.cursor()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
conn = Database.connect(**conn_params)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/MySQLdb/__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "/root/.pyenv/versions/2.7.14/lib/python2.7/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

解决办法:

https://blog.csdn.net/chenguolinblog/article/details/19421909

vi 根目录:setting.py
于是改成了以下的代码就ok了,实际上就是localhost的问题,只要替换为127.0.0.1即可

然后新开一个窗口,重要
重新运行python manage.py runserver

#######

[root@pythontest check_alarm]# python main_check.py
2018-12-25 21:51:05,157 - main_check.py[line:793] - INFO: 清除osinfo表无效监控数据
mysql execute: (2003, "Can't connect to MySQL server on '192.168.48.50' (110)")
mysql execute: (2003, "Can't connect to MySQL server on '192.168.48.50' (110)")

另外check_alarm/config/db_monitor.conf 也要mysql server 地址也要改

##########
Traceback (most recent call last):
File "main_check.py", line 881, in <module>
alarm.alarm()
File "/app/python/project/db_monitor-master/check_alarm/alarm.py", line 189, in alarm
group by tags, host, port, service_name) t where cnt_all > %d ''' %(tags,100,num_max)
UnboundLocalError: local variable 'tags' referenced before assignment

解决方法:
copy windows main_check.py to linux .

###############
2018-12-25 22:18:40,537 - main_check.py[line:528] - ERROR: ora11g_test 数据库连接失败:DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help

解决方法
1.

find / -name libclntsh.so
/home/db/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so

2.
export LD_LIBRARY_PATH=/home/db/oracle/product/11.2.0/dbhome_1/lib:$LD_LIBRARY_PATH
export ORACLE_HOME=/home/db/oracle/product/11.2.0/dbhome_1

###########

http://127.0.0.1:8000/admin

添加用户和管理权限

###########1229

#######如何传递vies函数的变量到模板
https://code.ziqiangxuetang.com/django/django-template2.html

view function -> function.name.html view 中指定返回模板名字
在视图中(views)我们传递了一个字符串名称是 string 到模板 home.html,在模板中这样使用它:

实例二,讲解了基本的 for 循环 和 List内容的显示

views.py

def home(request):
TutorialList = ["HTML", "CSS", "jQuery", "Python", "Django"]
return render(request, 'home.html', {'TutorialList': TutorialList})
在视图中我们传递了一个List到模板 home.html,在模板中这样使用它:

home.html

教程列表:
{% for i in TutorialList %}
{{ i }}
{% endfor %}

2、model 中的queryset debug

https://code.ziqiangxuetang.com/django/django-queryset-advance.html

开始之前我们修改一个 settings.py 让Django打印出在数据库中执行的语句

settings.py 尾部加上

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG' if DEBUG else 'INFO',
},
},
}

python manage.py shell

>>> from oracle_mon.models import TabOracleServers
>> TabOracleServers.objects.all().order_by('tags')
>> print str(TabOracleServers.objects.all().order_by('tags'))

>>> for m in a:
... print (m.tags)
...

QuerySet 是可迭代的,比如:

es = Entry.objects.all()
for e in es:
print(e.headline)

############20181231

1.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

python2 manage.py makemigrations
python2 manage.py migrate

check migration/db.log

2.
insert into check_list(check_tag,check_type,server_tag,begin_time,end_time) values(%s,%s,%s,%s,%s)"
value = (file_tag,'Oracle数据库',','.join(select_tags),begin_time,end_time)

mysql execute: (1364, "Field 'id' doesn't have a default value")

solution:
https://blog.csdn.net/u012110719/article/details/41850587
AUTO_INCREMENT PRIMARY KEY,
ALTER TABLE `check_list` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT;

3.
mysql execute: (1364, "Field 'chk_time' doesn't have a default value")

find the insert sql,insert add column and value
insert into
chk_time ->%s -> datetime.datetime.now()

或者

https://www.cnblogs.com/os-python/p/6773499.html
想要解决问题就需要知道在mysql5.7中,启用了严格模式:
在配置文件中 /etc/mysql/my.cnf 中找到:
sql-model=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
修改为:sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
然后重启mysql,在重新同步模型到数据库

4.
URL ->view function -> function.name.html view 中指定返回模板名字

url(r'^checklist_del/', frame.checklist_del),

add views.py
@login_required(login_url='/login')
def checklist_del(request):
check_tag = request.GET.get('check_tag')
print check_tag
models_frame.CheckList.objects.filter(check_tag=check_tag).delete()
return HttpResponseRedirect('/my_check/')

3.
pip download --only-binary=:all: --platform linux_x86_64 --python-version 27 --implementation cp -d D:\temp\zab pyenv

python django 基本测试 及调试 201812的更多相关文章

  1. python django 基本测试 及调试

    #########20181110from django.db import modelsfrom blog.models import Article, Author, TagAuthor.obje ...

  2. python+Django+test 测试数据库生成报错

    前提: 使用Django自带的test进行单元测试. 问题描述: 运行:python manage.py test,报错,出现数据库乱码的现象,报错如下: Creating test database ...

  3. python学习(十一)测试和调试

    最近学习了python的错误处理和几种测试方法 1 try except 可以通过try except方式捕捉异常 try: print('try...') r = 10/0 print('resul ...

  4. python django 基本测试

    http://www.runoob.com/django/django-model.html django-admin startapp TestModel /models.py from djang ...

  5. 测试开发:Python+Django实现接口测试工具

    Python+Django接口自动化 引言: 最近被几个公司实习生整自闭了,没有基础,想学自动化又不知道怎么去学,没有方向没有头绪,说白了其实就是学习过程中没有成就感,所以学不下去.出于各种花里胡哨的 ...

  6. Python:笔记(5)——错误、调试和测试

    Python:笔记(5)——错误.调试和测试 错误处理 1.TRY语句 这个和Java中的语法是及其相似的,catach换成except. 说明:同样,不管有没有错误,fianlly都会执行的! 补充 ...

  7. python测试与调试提示

    测试与调试提示 2.1 在交互模式输入一个python语句就会执行一个.在调试程序时,这种模式尤其有用. 2.2 在一个文件调用python解释器后,解释器会在文件中的最后一个语句执行之后推出.然而, ...

  8. 基于Python+Django的Kubernetes集群管理平台

    ➠更多技术干货请戳:听云博客 时至今日,接触kubernetes也有一段时间了,而我们的大部分业务也已经稳定地运行在不同规模的kubernetes集群上,不得不说,无论是从应用部署.迭代,还是从资源调 ...

  9. python Django教程 之 安装、基本命令、视图与网站

    python  Django教程  之 安装.基本命令.视图与网站 一.简介 Django 中提供了开发网站经常用到的模块,常见的代码都为你写好了,通过减少重复的代码,Django 使你能够专注于 w ...

随机推荐

  1. hibernate 对象OID

    它是hibernate用于区分两个对象是否是同一个对象的标识. 我们都知道,虚拟机内存区分两个对象看的是内存的地址是否一致.数据库区分两个对象,靠的是表的主键.hibernate负责把内存中的对象持久 ...

  2. ElasticSearch 入门(转)

    最大的特点: 1. 数据库的 database, 就是  index 2. 数据库的 table,  就是 tag 3. 不要使用browser, 使用curl来进行客户端操作.  否则会出现 jav ...

  3. 添加超级链接为什么用a标签

    a是anchor的简写,中文意思是锚点,而锚点的引申意思是连接,link已经被html占用了,只能用a来表示连接了.

  4. C++文件流打开标识符.RP

    ofstream流,以ios::app打开(或者“ios::app|ios::out”),如果没有文件,那么生成空文件:如果有文件,那么在文件尾追加.以ios::app|ios::in打开,不管有没有 ...

  5. RGB转灰度的几种算法

    这里我用的摄像头是OV2640,这款摄像头的像素是200万.通过对摄像头拍摄图像的进行图像的转化,先把图像的格式转化为RGB565,然后在进行灰度的转化,最后进行二值化处理,设定阈值,进行二值化的处理 ...

  6. 关于文本PDG的字体

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2008.08.03 有不少人在问为什么有些文本PDG在SSREADER里看到的是宋体,在Acobat里看到的是黑体,其实原因 ...

  7. 与HDFS交互- By java API编程

    环境(ubuntu下) jdk eclipse jar(很烦,整了很久才清楚) - 导包方法 查看:https://www.cnblogs.com/floakss/p/9739030.html ()” ...

  8. nginx的worker_processes优化

    nginx的worker_processes参数来源: http://bbs.linuxtone.org/thread-1062-1-1.html分享一:搜索到原作者的话:As a general r ...

  9. 关于javascript数据存储机制的一个案例。

    之前在学习js的结合性的时候,我有点不太明白,在网上找到一个比较经典的C语言优先级结合性的案例,就是下边这一个.本想在js之中测试一番,结果竟然发现得出的结果和网上的不一样,这令我百思不得其解,后经高 ...

  10. Python 之 装饰器

    装饰器 中的“器”代指函数 所以装饰器本质是函数,用来装饰其它函数.例如:为其它函数添加其他功能 实现装饰器需要的知识:  高阶函数+嵌套函数 == 装饰器 1.函数就是“变量” 函数就是“变量”说的 ...