TA的每日心情 | 无聊 2024-9-19 09:07 |
---|
签到天数: 11 天 连续签到: 2 天 [LV.3]测试连长
|
- <span class="k">def</span> <span class="nf">requestsMethodForPost</span><span class="p">(</span><span class="n">param</span><span class="p">):</span>
- <span class="n">url</span> <span class="o">=</span> <span class="n">upGradeUrl</span> <span class="o">+</span> <span class="s">'?'</span>
- <span class="n">request</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">param</span><span class="p">)</span>
- <span class="n">response</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">text</span>
- <span class="k">print</span> <span class="n">response</span>
- <span class="n">respDic</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
- <span class="k">return</span> <span class="n">respDic</span>
复制代码 大神们,我用python做接口自动化测试,遇到这么一个问题,在用requests中post请求的时候,参数中会带有中文,然后我就直接把中文传进去了:
- <span class="n">params</span> <span class="o">=</span> <span class="p">{</span>
- <span class="s">'from'</span><span class="p">:</span><span class="s">'internal'</span><span class="p">,</span>
- <span class="s">'gps_type'</span><span class="p">:</span><span class="s">'baidu'</span><span class="p">,</span>
- <span class="s">'lat'</span><span class="p">:</span><span class="s">'40.018597'</span><span class="p">,</span>
- <span class="s">'lng'</span><span class="p">:</span><span class="s">'116.476326'</span><span class="p">,</span>
- <span class="s">'mac'</span><span class="p">:</span><span class="s">'b4:30:52:5e:6d:61'</span><span class="p">,</span>
- <span class="s">'model'</span><span class="p">:</span><span class="s">'HUAWEI-HUAWEI C8817E'</span><span class="p">,</span>
- <span class="s">'name'</span><span class="p">:</span><span class="s">'先生'</span><span class="p">,</span>
- <span class="s">'order_id'</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">order_id</span><span class="p">,</span>
- <span class="s">'os'</span><span class="p">:</span><span class="s">'HUAWEI19,4.4.4'</span><span class="p">,</span>
- <span class="s">'phone'</span><span class="p">:</span><span class="s">'13000000090'</span><span class="p">,</span>
- <span class="p">}</span>
复制代码 然后,我就post出这个请求,但是在控制台,这个中文被直接自动转换为'\xe5\x85\x88\xe7\x94\x9f',导致这个传参一直是错误的,服务端会去校验你传入的值是否为正确编码格式,而python默认不会直接传入中文数据,这个有人遇到过吗
|
|