python
beta_safe
这个作者很懒,什么都没留下…
展开
-
控制台执行python脚本报错问题:ModuleNotFoundError: No module named ‘xxx‘
报错日志:Traceback (most recent call last):File "/Users/xxx/xxx/Project/python/xxx/xxx_req/xxx.py", line 15, in <module>from xxx import xxx_pb2_grpc, xxx_pb2ModuleNotFoundError: No module named 'xxx'from xxx import xxx_pb2_grpc, xxx_pb2Modu原创 2021-12-31 11:39:32 · 766 阅读 · 0 评论 -
python3 grpc client添加metadata方式
metadata = [('xx-service','xxx_test')]stub = xxx_pb2_grpc.xxxStub(channel)request_data = xxx_pb2.Requestxxx(xxx_id=12345678, xxx_model="小")print(type(request_data))print(request_data)response = stub.xxx(request_data, metadata=metadata)原创 2021-12-21 20:13:41 · 712 阅读 · 0 评论 -
python3 grpc client 调用go grpc server的一种方式
第一步:安装依赖包googleapis-common-protos==1.54.0grpcio==1.42.0grpcio-tools==1.42.0protobuf==3.19.1six==1.16.0pip3.9 install grpcio pip3.9 install grpcio-toolspip install googleapis-common-protos第二步:写client# coding=utf-8ixxxort jsonixxxort g原创 2021-12-21 17:46:43 · 971 阅读 · 0 评论 -
django单元测试
可以用django自带脚本manage.py驱动执行例如:venv/bin/python3 manage.py TestService单元测试源码如下:from django.core.management.base import BaseCommandfrom xxx.services.user.UserService import UserServicefrom xxx.services.record.RecordService import RecordService.原创 2021-12-17 11:56:15 · 542 阅读 · 0 评论 -
django orm常见错误raise AppRegistryNotReady(“Apps aren‘t loaded yet.“)RuntimeError: Model class models等等
错误一:ValueError: Cannot assign "<QuerySet [<User: user>]>": "SwitchRecord.user_id" must be a "User" instance.原因:# 外键django用户idclass SwitchRecord(models.Model): user_id = models.ForeignKey('User', on_delete=models.SET(0))解决方法:传入.原创 2021-12-17 11:51:45 · 1441 阅读 · 0 评论 -
django3.1发送邮件指定html正文:content_subtype = “html“
django3.1发送可替换内容类型在电子邮件中包含多个版本的内容可能很有用; 经典的例子是同时发送消息的文本格式版本和HTML格式版本。 Django的电子邮件库的EmailMultiAlternatives类可实现该功能。 作为EmailMessage的子类,它有一个attach_alternative()方法,用于在电子邮件中包含邮件正文的其它版本。它的所有其他方法(包括类初始化)直接继承EmailMessage。可以这样发送文本和HTML的组合:from django.core..原创 2021-06-01 11:50:35 · 242 阅读 · 0 评论 -
python字符串转成字典报错原因,必须使用单引号’‘
原创 2021-05-31 11:12:45 · 534 阅读 · 0 评论 -
crontab+shell定时执行pytest
pytest必须使用绝对路径11 9 * * * sh /xxx.sh /xxx/xxx.html /xxx/usr/local/bin/pytest /xxx/xxxx原创 2021-04-27 15:35:26 · 255 阅读 · 0 评论 -
python3读取txt行
1:readline() 1 2 3 4 5 6 7 file = open("sample.txt") while 1: line = file.readline() if not line: break pass # do something file.close() 一行一行得从文件读数据,显然比较慢;不过很省内存;测试读10M的sa...翻译 2020-10-19 17:12:52 · 696 阅读 · 0 评论 -
webtest遇到的问题window.navigator.webdriver如何设置为undefined
window.navigator.webdriver如何设置为undefined# 设置开发者模式options = webdriver.ChromeOptions()# 此步骤很重要,设置为开发者模式,防止被各大网站识别出来使用了Seleniumoptions.add_experimental_option('excludeSwitches', ['enable-automation'])# driver = webdriver.Chrome(options=options)bro.原创 2020-07-31 21:10:28 · 1322 阅读 · 1 评论 -
python3占位符后跟浮点型保留小数位数意义%0.2f
要保留两位该用%0.2f这个点是区分宽度和几位小数而已,不是真正的小数点;即%a.bf表示宽度为a,若超出按照实际的来;b表示有b位小数原创 2019-07-18 11:34:53 · 7445 阅读 · 0 评论 -
Mac下PyCharm快捷键
Mac键盘符号和修饰键说明⌘ Command ⇧ Shift ⌥ Option ⌃ Control ↩︎ Return/Enter ⌫ Delete ⌦ 向前删除键(Fn+Delete) ↑ 上箭头 ↓ 下箭头 ← 左箭头 → 右箭头 ⇞ Page Up(Fn+↑) ⇟ Page Down(Fn+↓) Home Fn + ← End Fn + → ⇥ 右制表符(T...原创 2023-02-17 09:54:54 · 926 阅读 · 1 评论 -
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
Traceback (most recent call last):File "/home/xiaoduc/.pyenv/versions/3.5.0/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 228, in _error_catcheryieldFile "/ho...转载 2018-08-08 19:54:46 · 26691 阅读 · 4 评论 -
python爬取ajax请求,返回的json数据格式化报错json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
python爬取ajax请求,返回Json数据中带有<html><head></head><body><prestyle="word-wrap: break-word; white-space: pre-wrap;"></pre></body></html>标签解决方原创 2018-05-25 20:32:46 · 45997 阅读 · 0 评论 -
python核心编程,使用了twisted.internet类创建一个简单的半双工聊天程序
Server部分:'''Created on 2018年5月6日一个时间戳TCP服务器,他使用了twisted.internet类@author: Administrator'''from twisted.internet import protocol,reactorfrom time import ctimefrom hexinbiancheng.utils.tsTclntEntity imp...原创 2018-05-06 23:14:44 · 445 阅读 · 0 评论 -
编码错误UnicodeDecodeError at / 'utf-8' codec can't decode byte 0xb1 in position 30: invalid start byte
类似这种UnicodeDecodeError at / 'utf-8' codec can't decode byte 0xb1 in position 30: invalid start byte编码错误,分析解决方案如下:1、查看控制台报错,找出引发错误的文件,任何程序员自己编写的文件都可能存在编码不一致(统一utf-8为例)的问题2、去notepad+中,把引发错误的文件转换编码,格式-&g...原创 2018-04-26 00:11:59 · 2173 阅读 · 0 评论 -
AttributeError: 'callable_iterator' object has no attribute 'next',python3中迭代器的next()方法已变成__next__()
报错信息:Traceback (most recent call last): File "F:/unit1/01_03.py", line 149, in <module> g = it.next()AttributeError: 'callable_iterator' object has no attribute 'next'解决办法:将上述代码中调用next()的地方全...原创 2018-04-30 15:10:29 · 7156 阅读 · 2 评论