Tag Archives: Tencent cloud

[Solved] Tencent cloud SMS service error: FailedOperation.TemplateIncorrectOrUnapproved

1. Problem
an error occurs when sending a text message:

"Code":"FailedOperation.TemplateIncorrectOrUnapproved",
"Message":"template is not approved or request content does not match the approved template content"

2. Solution
the reason for the error is that the template content parameters are inconsistent with the set parameters. Set to consistent. As shown in the following figure, the template content has two parameters, so the templateparamset in the code should also set two parameters

    /* Template parameters: If no template parameters, set to empty */
    String[] templateParamSet = {"", "60"};
    req.setTemplateParamSet(templateParamSet);

[Solved] Huawei OBS Python SDK download picture error: nosuchkey

Background:

In the past, Huawei OBS was used to download pictures (that is, to view pictures through a browser), and the address was used to access OBS directly.
for example,
endpoint: obs-example-domain.cn
picture name: QCX% 2F1% 2f20210804% 2f2db3c4bb-0c2c-4c3c-84e0-7e131c1e8db61628047890560.jpg

Access address:

http://obs-example-domain.cn/qcx%2F1%2F20210804%2F2db3c4bb -0c2c-4c3c-84e0-7e131c1e8db61628047890560. jpg

WGet can download pictures from the above address.

However, if you use Python SDK to access, an error will be reported:


AK = 'PLAU4DD8EYVXSA****UL'
SK = 'MdNZCKgSwt9Qgq6ZXtaF7wtZOd8********xEiv'
server = "http://obs-example-domain.cn"
bucketName = 'qcx'
obsClient = ObsClient(access_key_id=AK, secret_access_key=SK, server=server)
name = "qcx%2F1%2F20210804%2F2db3c4bb-0c2c-4c3c-84e0-7e131c1e8db61628047890560.jpg"
resp = obsClient.getObject(bucketName, name, loadStreamInMemory=True)
print(resp.body)

Output: the specified key does not exist

In the above procedures: name = QCX% 2F1% 2f20210804% 2f2db3c4bb-0c2c-4c3c-84e0-7e131c1e8db61628047890560 jpg

Solution:

The picture name above is actually URLEncode. The original string urlcode can obtain:

qcx/1/20210804/2db3c4bb-0c2c-4c3c-84e0-7e131c1e8db61628047890560. jpg

Change the name in the above code to the picture name after URLDecode, that is:

name = "qcx/1/20210804/2db3c4bb-0c2c-4c3c-84e0-7e131c1e8db61628047890560.jpg"

You can get the picture correctly.

The function completion code

Picture browsing completed line:

Browser request img URL -> nginx -> API (with SK AK) – > obs -> Response API – > nginx -> browser

Python 2.7 (only this version is available on the server and cannot be upgraded to 3.X)

#coding=utf-8
from BaseHTTPServer import BaseHTTPRequestHandler
import urllib
import cgi
import os
import urllib
# print urllib.unquote('%E4%B8%89%E7%94%9F%E4%B8%89%E4%B8%96')

from obs import ObsClient

AK = 'PLAU4DD8EYVXSA****UL'
SK = 'MdNZCKgSwt9Qgq6ZXtaF7wtZOd8********xEiv'
server = "http://obs.cn-dchlw-1.digitalgd.com.cn"
bucketName = 'qcxx'
obsClient = ObsClient(access_key_id=AK, secret_access_key=SK, server=server)

cwd = os.getcwd()

class ObsHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        path = urllib.unquote(self.path)
        buf = ""
        query_list = path.split("/")  #auto urldecode
        #print(query_list)
        if query_list[1] == "obs":
            name = "/".join(query_list[3:]).replace("?","")   # for online
            #name = urllib.unquote(name)
            resp = obsClient.getObject(bucketName, name, loadStreamInMemory=True)
            if resp.status < 300: 
                self.send_response(200) 
                buf = resp.body.buffer
            else: 
                self.send_response(400)
        self.end_headers()
        self.wfile.write(buf)
       
 
def StartServer():
    from BaseHTTPServer import HTTPServer
    sever = HTTPServer(("",12000),ObsHandler)
    sever.serve_forever()
  
  
if __name__=='__main__':
    StartServer()

Installing rabbitmq on alicloud server

1. Install Erlang
Because RabbitMQ is developed in the Erlang language, you install Erlang first

yum install erlang

Download the RPM package

 wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-3.6.15-1.el7.noarch.rpm

3. Install after downloading

yum install rabbitmq-server-3.6.15-1.el7.noarch.rpm

4. Restart the service after installation

service rabbitmq-server start

5. Check service status

service rabbitmq-server status

6. Install the plug-in

/sbin/rabbitmq-plugins enable rabbitmq_management 

Restart the service

service rabbitmq-server restart

At this point, you can go to http://ip:15672 to access the page. The default password is “guest/guest”.
However, starting with version 3.3.0, access other than using guest/guest to log in to localhost is prohibited. The solution is to find
Rabbitmq_server-3.6.15 /ebin/ Rabbitmq_server-3.6.15 /ebin/ Rabbit.app

{loopback_users, [<<"guest">>]},

Is amended as:

{loopback_users, []},

Then restart it.
7. Access