我正在使用pathlib.Path作为os.path的替代方案,并尝试将其用于django项目中的目录路径,但是我尝试创建迁移时发生了错误:
"return database_name == ': memory:' or 'mode = memory' in database_name
TypeError: argument of type 'PosixPath' is not iterable "
和我的基本目录:
BASE_DIR = Path(__file__).parent.parent.parent
数据库连接:
BAS
我最近迁移到Python3.5。这段代码在Python2.7中运行正常:
with open(fname, 'rb') as f:
lines = [x.strip() for x in f.readlines()]
for line in lines:
tmp = line.strip().lower()
if 'some-pattern' in tmp: continue
# ... code
升级到3.5之后,我得到了:
TypeError:需要一个类似字节的对象,而不是'str‘。
错误出现在最后一行(模
尝试将Django-MongoDB开发环境迁移到生产环境
从web界面不断收到以下错误:
ImproperlyConfigured at /
port must be an instance of int
在终端上,如果我运行
python manage.py syncdb
File "/home/user/lib/python-environments/djangomongo/local/lib/python2.7/site-packages/pymongo/connection.py", line 209, in __init__
我想创建一个套接字通信,但是如果我运行以下脚本,会出现一个错误:TypeError: a bytes-like object is required, not 'str'
import socket
import time
UDP_IP = "192.168.1.169"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # INTERNET
socket.SOCK_DGRAM) # UDP
while True:
v = input("Message: ")
我在试这个
from django.utils.text import slugify
In [8]: mystr = "This is john"
In [9]: slugify(mystr)
我得到了这个错误
TypeError: must be unicode, not str
如果我用这个
然后,from django.template.defaultfilters import slugify可以工作,但它不需要将underscores转换为hyphens,如果有dots,则简单地删除它
import urllib.request
import re
f = urllib.request.urlopen('http://www.geekynu.cn/')
html = f.read()
title = re.search('<title>(.*?)</title>', html)
print(title)
#print(title.decode('utf-8')) //I had try to solve by this code.
Python3.5当我使用re.search()读取网页标题时,错误是
我目前正在使用Freeswitch和它的 (通过)。例如:
from ESL import ESLconnection
cmd = 'uuid_kill %s' % active_call # active_call comes from a Django db and is unicode
con = ESLconnection(config.HOST, config.PORT, config.PWD)
if con.connected():
e = con.api(str(cmd))
else:
logging.error('Couldn\'
我正在使用MariaDB内存引擎。我在max_heap_table_size中定义了my.cnf,重新启动了数据库服务。现在,我运行迁移并获得:
django.db.utils.ProgrammingError: Storage engine MEMORY doesn't support BLOB/TEXT columns
我的错误模式是:
class Department(models.Model):
name = models.CharField(max_length=100)
tag = models.CharField(max_length=10)
dt
下面的代码给我带来了问题:
with open(fname, 'wb') as f:
for p, values in params:
s = str.encode("%s" % p)
print("the type is:", type(s))
print(s)
print(s, file=f)
产出如下:
the type is: <class 'bytes'>
b'myfancystring'
...
TypeError: a
我正在尝试使用Django Admin删除一个用户,但是我得到了这个错误:
TypeError: coercing to Unicode: need string or buffer, User found
导致此错误的原因是什么?
完全错误:
TypeError at /admin/auth/user/
coercing to Unicode: need string or buffer, User found
Request Method: POST
Request URL: http://www.domain.com/admin/auth/user/
Exception Type:
我正在尝试将别人10年前的python2脚本转换为python3。我已经解决了大部分问题,但这个问题卡住了。这是一条线
(a,b,c,d) = unpack('!HIIH', someData)
当运行的时候,我得到了这个:
TypeError: a bytes-like object is required, not 'str'
网上有很多关于这个问题的文章,但没有一个正确的答案。我尝试过在someData对象上以各种方式使用'bytes‘函数,但都不起作用。
更多的信息是,我相信someData对象的起源是通过另一个模块中的这段代码:
e = str
显然,我正在使用telnetlib.expect()与一个以字节串响应的设备进行接口。除非我在传递给expect()的正则表达式(预编译或文字)中使用字节字符串,否则将生成一个异常:TypeError: cannot use a string pattern on a bytes-like object。然而,pycodestyle抱怨这是W605 invalid escape sequence '\d',进一步的阅读使我认为这将成为将来的Python语法错误。
总结如下:
telnetlib.expect([b'\d']) # OK, but W065
tel
我正在尝试编写一个server-client程序,在这个程序中,server将监听client's消息,并根据消息进行响应。我用username和content从client发送一条消息,server接受它并打印一条消息发送到client,直到这里一切正常。但是当涉及到发送消息时,server将抛出错误:
`TypeError: byte indices must be integers or slices, not str`
看起来这行是有问题的,但我不确定...
`clientsocket.send(msg['header'] + msg['data