zoukankan      html  css  js  c++  java
  • python3 报错集合

    1.格式

    message = "GET / HTTP/1.1
    
    "
    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)
    公众号请关注:侠之大者
  • 相关阅读:
    VS快捷键
    eclipse快捷键(shift+ctrl+l能出来所有的快捷键)
    永远不要觉得自己代码有多6
    winform中使用webBrowser时如何与JS交互
    HTML CSS
    HTTP 协议 session cookie
    [Python3]Python官方文档-Python Manuals
    [python3]PyCharm编辑器
    Loadrunner上传文件与下载文件脚本
    Spotlight安装
  • 原文地址:https://www.cnblogs.com/kamil/p/5259727.html
Copyright © 2011-2022 走看看