python 使用记录及问题

编码问题 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

转载自cnblog
Unicode的编码问题,读取文件时使用的编码默认是ascii而不是utf8,所以报错

在代码中加上几句即可:

import sys
reload(sys)
sys.setdefaultencoding('utf8')

安装 psutil SystemExit: error: command 'gcc' failed with exit status 1

OS: CentOS Linux release 8.0.1905 (Core)
Python: 3.6
Clues:SystemExit: error: command 'gcc' failed with exit status 1
Problem solved.

ym install -y gcc gcc-c++ libgcc platform-python-devel

giithub issue

查询域名解析

查询返回的地址是数组

➜  go_httpbin git:(main) ✗ ipython
Python 3.7.3 (default, Mar  6 2020, 22:34:30)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import socket

In [2]: socket.getaddrinfo('www.baidu.com',None)
Out[2]:
[(<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('110.242.68.3', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('110.242.68.3', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('110.242.68.4', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('110.242.68.4', 0))]
posted @ 2020-04-04 13:57  hiyang  阅读(332)  评论(0编辑  收藏  举报