#####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. STM32 C++编程 003 USART(串口)类

    使用 C++ 语言给 STM32 编写一个 Usart 类 我使用的STM32芯片:STM32F103ZET6 我们使用的STM32库版本:V3.5.0 注意: 想学习本套 STM32 C++编程 的 ...

  2. 算法Sedgewick第四版-第1章基础-003一封装日期

    1. package ADT; import algorithms.util.StdOut; /**************************************************** ...

  3. 深、浅copy

    深.浅copy多用于列表 浅copy:第一层中不变的数据是独立的,可变类型元素指向同一块内存地址 l1 = [1,2,3,["a","b"]] l2 = l1. ...

  4. python--爬虫基础

    http://files.cnblogs.com/files/Kobe10/Python__%E7%88%AC%E8%99%AB%E5%9F%BA%E7%A1%80.pdf

  5. SPOJ - AMR11H Array Diversity (水题排列组合或容斥)

    题意:给定一个序列,让你求两种数,一个是求一个子序列,包含最大值和最小值,再就是求一个子集包含最大值和最小值. 析:求子序列,从前往记录一下最大值和最小值的位置,然后从前往后扫一遍,每个位置求一下数目 ...

  6. C# 与Java初始化顺序及异同(转)

    C#初始化顺序 类成员变量初始化先于类的构造函数 静态成员变量先于实例变量 子类成员变量先于父类成员变量(java相反) 父类构造函数先于子类构造函数 参考实例: using System; //us ...

  7. Appium的常用定位方法

    使用uiautomatorviewer.bat工具来找到属性定位元素,在SDK的tools目录下找到该工具,双击打开.左边框内展示app的界面元素,右上角框内展示元素的层级关系,右下角框内展示元素的属 ...

  8. UWP&WP8.1 中文网页字符乱码 字符乱码 UTF-8转GBK 解决方法

    UWP 方法 async void Download() { /*新建HttpClient*/ HttpClient web_ = new HttpClient(); /*使用HttpClient的G ...

  9. mysql在linux下的安装与优化

    mysql5.6 http://www.cnblogs.com/bookwed/p/5896619.html mysql5.7 http://blog.csdn.net/wb96a1007/artic ...

  10. 「BZOJ 3270」博物馆「高斯消元」

    应该算高斯消元经典题了吧. 题意:一个无向连通图,有两个人分别在\(s,t\),若一个人在\(u\),每一分钟有\(p[u]\)的概率不动,否则随机前往一个相邻的结点,求在每个点相遇的概率 题解: 首 ...