草庐IT

bytes_received

全部标签

python - 使用pyinstaller生成exe文件报错-typeerror : expected str, bytes or os.PathLike object, not NoneType

我正在尝试使用pysinstaller和Python3.7.2从.py文件构建一个.exe文件。它适用于Python3.6;然后我重新安装了最新版本的Python(3.7.2)并尝试生成一个exe文件,但是pyinstallerbarfs。下面是我得到的错误报告。(venv)C:\Users\user\Desktop\untitled1>pyinstallertest.py53INFO:PyInstaller:3.453INFO:Python:3.7.254INFO:Platform:Windows-10-10.0.17134-SP058INFO:wroteC:\Users\user\

python - 从 asyncio.Protocol.data_received 调用协程

这类似于Callingcoroutinesinasyncio.Protocol.data_received但我认为这需要一个新问题。我有一个像这样设置的简单服务器loop.create_unix_server(lambda:protocol,path=serverSocket)如果我这样做,它工作正常defdata_received(self,data):data=b'datareply'self.send(data)我的客户得到回复。但我无法让它与任何类型的asyncio调用一起工作。我尝试了以下所有方法,但均无效。@asyncio.coroutinedefgo(self):yiel

python - json.dump - UnicodeDecodeError : 'utf8' codec can't decode byte 0xbf in position 0: invalid start byte

我有一个字典data我存储了:key-事件IDvalue-此事件的名称,其中value是UTF-8字符串现在,我想把这张map写到一个json文件中。我试过这个:withopen('events_map.json','w')asout_file:json.dump(data,out_file,indent=4)但这给了我错误:UnicodeDecodeError:'utf8'codeccan'tdecodebyte0xbfinposition0:invalidstartbyte现在,我也试过:withio.open('events_map.json','w',encoding='utf

python 2.7 等效于内置方法 int.from_bytes

我正在尝试使我的项目与python2.7和3兼容,而python3具有内置方法int.from_bytes。python2.7中是否存在等效项,或者更确切地说,使此代码与2.7和3兼容的最佳方法是什么?>>>int.from_bytes(b"f483",byteorder="big")1714698291 最佳答案 您可以将其视为一种编码(特定于Python2):>>>int('f483'.encode('hex'),16)1714698291或者在Python2和Python3中:>>>int(codecs.encode(b'f4

python - Django : RunTimeWarning : DateTimeField received a naive datetime while time zone support is active

我正在尝试基于djangocart测试购物车创建但是当我尝试创建购物车时出现此错误:RunTimeWarning:DateTimeFieldreceivedanaivedatetimewhiletimezonesupportisactive我做了一些研究,但无法解决datetime.datetime.now()的问题test_views.py在我的测试目录中:fromdjango.testimportTestCase,Client,RequestFactoryimportunittestfromdjango.contrib.auth.modelsimportUser,Anonymous

python - 'bytes' 对象没有属性 'encode'

在将每个文档插入集合之前,我试图存储盐和散列密码。但是在对盐和密码进行编码时,它显示以下错误:line26,inbefore_insertdocument['salt']=bcrypt.gensalt().encode('utf-8')AttributeError:'bytes'objecthasnoattribute'encode'这是我的代码:defbefore_insert(documents):fordocumentindocuments:document['salt']=bcrypt.gensalt().encode('utf-8')password=document['pa

python - Python如何将bytes转为float?

我有以下代码片段:#!/usr/bin/envpython3print(float(b'5'))它打印5.0没有错误(在使用utf-8编码的Linux上)。我很惊讶它没有给出错误,因为Python不应该知道字节对象使用什么编码。有什么见解吗? 最佳答案 当传递一个bytes对象时,float()将对象的内容视为ASCII字节。这在这里就足够了,因为从字符串到float的转换只接受ASCII数字和字母,加上.和_无论如何(唯一允许的非ASCII代码点是空格代码点),这类似于int()处理bytes输入的方式。在幕后,实现是这样做的:因

java - Java String.getBytes() 和 Python string -> bytes 之间的行为完全相同吗?

在我的Java代码中有以下片段:Stringsecret="secret";byte[]thebytes=secret.getBytes();我想在python中得到完全相同的结果。我该怎么做?secret='secret'thebytes=?????????谢谢。编辑:此外,如果有Python2.x和3.x的解决方案会很有趣 最佳答案 这并不像乍看起来那么简单,因为Python历来将字节数组和字符串混为一谈。在Python3中,简短的回答是secret="secret"secret.encode()但是您应该阅读Python如何处

python - 子进程 "TypeError: a bytes-like object is required, not ' str'"

我正在使用来自apreviouslyaskedquestionafewyearsago的代码但是,我认为这已经过时了。尝试运行代码时,我收到了上面的错误。我仍然是Python的新手,所以我无法从类似的问题中得到太多的澄清。有谁知道为什么会这样?importsubprocessdefgetLength(filename):result=subprocess.Popen(["ffprobe",filename],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)return[xforxinresult.stdout.readlines()if"

python - create_string_buffer 抛出错误 TypeError : str/bytes expected instead of str instance

我正在尝试这个简单的ctypes示例并得到提到的错误>>>fromctypesimportcreate_string_buffer>>>str=create_string_buffer("hello")Traceback(mostrecentcalllast):File"",line1,inFile"C:\Python32\lib\ctypes\__init__.py",line59,increate_string_bufferbuf.value=initTypeError:str/bytesexpectedinsteadofstrinstance有谁知道我做错了什么吗?同样,我试图将