乱码:

以content字节流输出,解码成utf-8:

print(r.encoding)   # 查看返回的编码格式:

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

 

 

去掉Warning警告:

import urllib3

urllib3.disable_warnings()

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

 

 

错误处理:

403:拒绝或者禁止访问:须伪装头部(头部详情根据接口文档)

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1、服务器识别出为代码访问                :

1.1.代码访问的头部:User-Agent为python

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1.2.浏览器访问的头部:User-Agent为浏览器

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1.3.在头部加上User-Agent:

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2、伪装头部后仍然403:服务器校验Cookic              (Cookic有时效性)

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.1.代码访问时没有加Cookic

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.2.浏览器访问时有Cookic

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.3.在头部加上Cookic访问成功

python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

乱码:

以content字节流输出,解码成utf-8:

print(r.encoding)   # 查看返回的编码格式:

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

 

 

去掉Warning警告:

import urllib3

urllib3.disable_warnings()

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

 

 

错误处理:

403:拒绝或者禁止访问:须伪装头部(头部详情根据接口文档)

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1、服务器识别出为代码访问                :

1.1.代码访问的头部:User-Agent为python

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1.2.浏览器访问的头部:User-Agent为浏览器

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

1.3.在头部加上User-Agent:

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2、伪装头部后仍然403:服务器校验Cookic              (Cookic有时效性)

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.1.代码访问时没有加Cookic

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.2.浏览器访问时有Cookic

 python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

2.3.在头部加上Cookic访问成功

python接口自动化测试五:乱码、警告、错误处理
    


            
python接口自动化测试五:乱码、警告、错误处理

 

相关文章:

  • 2021-08-16
  • 2022-03-04
  • 2022-01-06
  • 2022-03-06
  • 2022-12-23
  • 2021-12-14
  • 2021-11-30
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-01-14
  • 2021-09-18
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案