首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >when i'm using python SDK for sent a post request?

when i'm using python SDK for sent a post request?

提问于 2019-08-01 09:08:25
回答 1关注 0查看 484

I want sent a post request

i have to use English ,becasue my RaspberryPi don't have pinyin

please use Cinese answer the question .

exception:

代码语言:js
AI代码解释
复制
[TencentCloudSDKException] code:AuthFailure.SignatureFailure message:The provided credentials could not be validated because of exceeding request size limit, please use new signature method `TC3-HMAC-SHA256`. requestId:92c2a31c-4afe-4f34-a9e2-dc4fe2b35fc8

my code:

代码语言:python
运行
AI代码解释
复制
# helloworld/helloworld/view.py
from PIL import Image
import uuid
from django.http import HttpResponse
import json
from picamera import PiCamera
from time import sleep
import random
import requests
import datetime
import os
import base64
import sys
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException 
from tencentcloud.iai.v20180301 import iai_client, models 

def get_size(file):
    # 获取文件大小:KB
    size = os.path.getsize(file)
    return size / 1024

def get_outfile(infile, outfile):
    if outfile:
        return outfile
    dir, suffix = os.path.splitext(infile)
    outfile = '{}-out{}'.format(dir, suffix)
    return outfile

def compress_image(infile, outfile='', mb=9000, step=10, quality=80):
    """不改变图片尺寸压缩到指定大小
    :param infile: 压缩源文件
    :param outfile: 压缩文件保存地址
    :param mb: 压缩目标,KB
    :param step: 每次调整的压缩比率
    :param quality: 初始压缩比率
    :return: 压缩文件地址,压缩文件大小
    """
    o_size = get_size(infile)
    if o_size <= mb:
        return infile
    outfile = get_outfile(infile, outfile)
    while o_size > mb:
        im = Image.open(infile)
        im.save(outfile, quality=quality)
        if quality - step < 0:
            break
        quality -= step
        o_size = get_size(outfile)
    return outfile, get_size(outfile)

def createAnImage():
    camera = PiCamera()
    # camera.start_preview()
    camera.rotation = 180
    sleep(2)

    fileNameArry = []
    for i in range(0, 5):
        fileNameArry.append(random.randint(1, 50))
    fileName = "".join(str(word) for word in fileNameArry)
    longFileName = "/home/pi/Desktop/images/" + fileName + ".jpg"
    camera.capture(longFileName)
    compress_image(longFileName)
    # camera.stop_preview()
    return longFileName

def imageToBase64(langFileName):
    
    with open(langFileName, 'rb') as f:
        base64_data = base64.b64encode(f.read())
        s = base64_data.decode()
        return s

def creatPerson(FileName,personName,personId):

    try:
        cred = credential.Credential("AKIDthNtIXWTczdCdxrJM9qLivxnRQRGFLbi", "5zIWZP3WouoPuENKLCrL5g6OVTGswuWL") 
        httpProfile = HttpProfile()
        httpProfile.endpoint = "iai.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = iai_client.IaiClient(cred, "ap-beijing", clientProfile)

        req = models.CreatePersonRequest()
        params = '{"GroupId":"group1","PersonName":"'+ personName +'","PersonId":"'+ personId +'","Image":"'+ imageToBase64(FileName) +'"}'
        req.from_json_string(params)

        resp = client.CreatePerson(req) 
        print(resp.to_json_string()) 

    except TencentCloudSDKException as err: 
        print(err) 


def addFamily(request):
    global return_json

    if request.is_ajax():

        data = json.loads(request.body.decode("utf8"))
        
        print(data)
        
        tencentReturnFlag = creatPerson()

        if BaiduReturnFlag == "0":
            return_json = {"msg": "添加成功"}
        else:
            return_json = {"msg": "添加失败"}
        
        os.remove(longFileName)

        return HttpResponse(json.dumps(return_json))
    
creatPerson(createAnImage(),"didi","201703204322")

回答 1

流星留步

发布于 2019-08-01 09:23:53

你这是签名过期,看起来是签名方法有问题。

和开发者交流更多问题细节吧,去 写回答
相关文章
The request sent by the client was syntactically incorrect
使用HttpUtil的doPostHttp方法发送请求时,收到了tomcat返回的以下错误信息:The request sent by the client was syntactically incorrect,debug了下发现发现tomcat返回了400错误:由于语法格式有误,服务器无法理解此请求
johnhuster的分享
2022/03/28
6280
App will crash when using the when keyword in a catch expression
We know that we can add a when keyword after a catch filter. But if there is another exception happened in the when expression, the app will totally crash.
walterlv
2023/10/22
1740
App will crash when using the when keyword in a catch expression
python使用request发送post请求
唯一Chat
2023/09/15
2890
Python Request get post 代理 基本使用
关于文件上传可参考我的这篇博客:requests post 文件上传https://blog.csdn.net/EXIxiaozhou/article/details/126975807
EXI-小洲
2022/12/13
4650
Python Request get post 代理 基本使用
python爬虫request如何提交request payload形式发送post请求
今天想用python自动获取表单的信息,但是提交请求是request payload的形式
SingYi
2022/07/14
1.9K0
python爬虫request如何提交request payload形式发送post请求
The request sent by the client was syntactically incorrect ()"解决办法
使用Spring MVC3框架时,可能会遇到这个问题,请求后台没有任何响应,页面显示
traffic
2020/04/09
2.3K0
When did I run that command?
When did I run that command 2020 $ echo "this prompt's time updates!" this prompt's time updates!
仇诺伊
2020/04/23
3460
When did I run that command?
Python Request POST 上传文件 Multipart/form-data
最后在分享一个web开发的技术网站,详细的介绍了请求头的各种参数:web开发技术网站 手机app抓包工具推荐:小黄鸟(HTTPCanary)
EXI-小洲
2022/12/13
2.5K0
Python Request POST 上传文件 Multipart/form-data
How to Add an API to your Web Service
Introduction APIs are a great way to extend your application, build a community, excite your users and get in on the Mashup Mania spreading across the web. While there’s plenty out there wanting in on the action, there’s a lot of questions about how to act
张善友
2018/01/29
7940
(译) Server-Sent Events: the alternative to WebSockets you should be using
当开发实时 web 应用时,WebSockets 可能是我们首先想到的。然而,Server Sent Events (SSE) 是通常会是一种更简单的替代方案。
Cloud-Cloudys
2023/10/21
5080
(译) Server-Sent Events: the alternative to WebSockets you should be using
How to Keep Environment Variables and PATH When Using SUDO
sudo tips How to keep Environment Variables when Using SUDO The trick is to add environment variables to sudoers file via sudo visudo command and add these lines: Defaults env_keep += "HOME" or and pay attention to the -E flag. This works: export HOME=/hom
happy123.me
2018/06/04
4390
nodejs 用request实现post请求
以下是使用 Node.js 和 Request 模块来实现 POST 请求的示例代码:
用户8703799
2023/05/19
1.4K0
c++发送post请求_request的post方法作用
RestSharp是一个轻量的,不依赖任何第三方的模拟Http的组件或者类库。RestSharp具体以下特性;支持net4.0++,支持HTTP的GET, POST, PUT, HEAD, OPTIONS, DELETE等操作,支持oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators等授权验证等。截止当前目前是github最高stars的http类库。
全栈程序员站长
2022/10/03
2K0
c++发送post请求_request的post方法作用
How to Create and Use Facebook Messenger Codes (June 2019)
How to Create and Use Facebook Messenger Codes (June 2019) By Gerardo Salandra What is a Messenger
Spanz
2019/06/02
7740
点击加载更多

相似问题

微信小程序端SDK,使用qcloud.request method如何POST数据到服务器端?

73.5K

TKE Python SDK?

1510

Python sdk TencentCloudSDKException报错?

24K

云点播, web端sdk上传, 接口返回 ugc upload | invalid request?

32.1K

.Net SDK 分片上传目前只支持1M吗?

0207
相关问答用户
腾讯 | 产品运营经理擅长5个领域
腾讯 | 服务生
腾讯 | 客户端研发擅长3个领域
腾讯云AI | 技术专家
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档