具体错误:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 73-74: Body ('测试') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

解决:
对请求参数进行编码处理:
示例代码:

import requests
import json
import re
import pymysql
from tool.Mysql_connect import Mysql_operation
from tool.get_token import Crm_token class test_demo(object):
def __init__(self):
self.op_mysql=Mysql_operation()
self.token=Crm_token()
def create_yixiang(self):
url='http://xxx/customerAdjunctAdd'
token=self.token.get_token()
headers={"Content-Type":'application/x-www-form-urlencoded',
"token":token}
try:
tel_num=self.op_mysql.sql_select('''select max(tel) from nc_customer_adjunct''')[0]['max(tel)'] #结果为str
except Exception as error:
print(error)
a=1
while a<3:
tel_num=int(tel_num)+1
a+=1
data='customer_type=1&source=1&course_name_id=41&tel=%d&customer_name=测试3.1&sex=0&school=测试1&intro_id=0'%(tel_num)
try:
request1=requests.request("POST",url=url,headers=headers,data=data.encode()) #encode对请求编码处理:不处理接口会返回数据解析错误
# print(data)
response1=request1.json()
print(headers)
print(response1)
except Exception as error:
print(error)
if __name__=="__main__":
Tm=test_demo()
Tm.create_yixiang()

python发起请求提示UnicodeEncodeError的更多相关文章

  1. python 发起HTTP请求

    因为微信公众号群发需要调用高级群发接口,其中涉及到python发起HTTP请求,现在将相关实现操作记录如下: 首先,HTTP请求分为GET和POST,如下所示: 首先是发起get 请求: # -*- ...

  2. python + requests发起请求,接口返回400,报错“Unexpected character encountered while parsing value: G. Path”

    完整报错信息如下: {'errors': {'': ["Unexpected character encountered while parsing value: G. Path '', l ...

  3. Python接口测试实战2 - 使用Python发送请求

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  4. Python网络请求urllib和urllib3详解

    Python网络请求urllib和urllib3详解 urllib是Python中请求url连接的官方标准库,在Python2中主要为urllib和urllib2,在Python3中整合成了urlli ...

  5. Photon Server 实现注册与登录(三) --- 前端UI设计和发起请求

    一.打开之前的测试项目.先将服务端代码编译一下,在 bin/Debug/目录下会发现有一个Common.dill.我们相应导入到前端使用.直接拖拽到相应地方 UI相应布局属于前端操作,这里就不做介绍了 ...

  6. 原始ajax发起请求并反馈

    在用户登陆的时候,离开用户.密码输入框即进行验证:ajax发起请求进行验证的: login.jsp代码: <%@ page language="java" contentTy ...

  7. python网页请求urllib2模块简单封装代码

    这篇文章主要分享一个python网页请求模块urllib2模块的简单封装代码. 原文转自:http://www.jbxue.com/article/16585.html 对python网页请求模块ur ...

  8. 小程序之发起请求 wx.request(object)的坑

    这是官方的API,然后官方的实例中 wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { ...

  9. goquery 添加header 发起请求

    goquery 添加header 发起请求 我们知道使用net/http 很容易发起GET or POST 请求:并且在发起http请求时候,可以很容易的对header进行干预 例如: client ...

随机推荐

  1. ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(七)之 图文,附件消息(2016-05-05 12:13)

    上一篇介绍了加好友的流程,这里不再赘述,不过之前的聊天只能发送普通文字,那么本篇就教你如何实现发送附件和图片消息.我们先对功能进行分析: 发送图片,附件,需要实现上传图片和附件的功能. textare ...

  2. Ubuntu 16.04 安装 IDEA

    1.下载地址:https://www.jetbrains.com/idea/download/#section=linux 选择without jdk版本下载 2.下载完成 解压 到 /opt下 先却 ...

  3. 【luogu P1972 [SDOI2009]HH的项链】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1972 真是不懂为什么要卡莫队! #include <cmath> #include <cs ...

  4. 关于css透明度的问题

    先看background和background-color background:可以设置背景颜色,背景图片,还有定位.默认background:no-repeat; background-color ...

  5. Django-rest-framework(二)serializers 使用

    简介 初次见到serializers文件,想必大家都会感到陌生,所以,我们不妨换个词来形容他的作用,那就是django 中的Form,这样是不是感觉熟悉了一点. 实际上,serializers 的作用 ...

  6. 工具类(为控件设置圆角) - iOS

    为了便于日常开发效率,因此创建了一些小的工具类便于使用.具体 code 如下:声明: /* 为控件添加边框样式_工具类 */ #import <UIKit/UIKit.h> typedef ...

  7. iOS10 开发权限适配设置 崩溃(上传打包后构建版本一直不显示)

    ios10 系统必须强制配置系统权限 如果不配置,调试的时候导致崩溃,还会引发包无效的问题,导致上传打包后构建版本一直不显示 解决方案1.在项目中找到info.plist文件,右键点击以 Source ...

  8. UML绘制活动图--客户来电咨询活动图

    选择Logic View–>New–>Activity Diagram 修改NewActivity为客户来电咨询 选择初始状态和终止状态(下图中上面是Start State,下面是End ...

  9. 【2018 ICPC焦作网络赛 G】Give Candies(费马小定理+快速幂取模)

    There are N children in kindergarten. Miss Li bought them N candies. To make the process more intere ...

  10. ABAP术语-Function Module

    Function Module 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/18/1071827.html General-purpose ...