python3 报错集合

it2022-05-06  29

1.格式

message = "GET / HTTP/1.1\r\n\r\n" s.sendall(message) TypeError: 'str' does not support the buffer interface 修正为 s.sendall(bytes(message,"utf8"))

 

2.语法

SyntaxError:invalid syntax . “语法错误:不正确的语法”。

 3.str

TypeError: encoding or errors without a string argument 格式不对 :

 4.套接字的成员函数send

套接字的成员函数send socket.send(bytes[, flags]) 形参为字节类型 socket.recv(bufsize[, flags]) Receive datafrom the socket. The return value is abytes object representing the data received.

 5,。

xxx.decode() 是把xxx按括号中的编码方式 解码成unicode xxx.encode() 是把unicode类型的xxx按括号中的编码方式 进行编码(所以如果xxx不是unicode,系统会采用默认编解码方式对xxx进行解码,然后再做如上的编码操作)

 6. urllib 获取中文

#!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: hello.py @time: 2016/4/13 10:18 """ from urllib.request import urlopen http = urlopen("http://www.cnblogs.com/kamil/") print(http.read().decode('UTF-8'))

 7.urllib发生url有中文

import urllib s=‘中文’ s=urllib.parse.quote(s) url='some english url character %s'%(s) urllib.request.urlopen(url)

 

转载于:https://www.cnblogs.com/kamil/p/5259727.html


最新回复(0)