写django 时候发现,作者为了保证最好的可用性,统一使用了unicode 编码。
使用django 中的模块,它会自动转为合适的类型。
而自己的代码如果直接去调用底层的接口,则可能出现错误。
例如在调用sockets.py这个底层的文件中的create_connection()方法时,传递二个参数,host,port.这两个参数在django中赋值是默认为unicode。而sockets则要求为int 或者 str
from django.utils.encoding import smart_unicode
from django.utils.encoding import smart_str
host=smart_unicode('192.168.10.1')
print type(host)
host=smart_str('192.168.10.1')
print type(host)
完美解决咯。