Python3 call Nowapi interface to implement the QR code generation tool

Source: Internet
Author: User
Tags urlencode

I python learning a rookie, with the learning of Python, feel python more and more fun, the last time with the interface query IP address, and see Youdao dictionary query, QR code generation interface-related methods, and made a simple attempt, it is quite fun indeed. So the whole process is recorded. Share here, for everyone to exchange study together.

1. Basic Environment

System: Windows 7

Development environment: Pycharm Python3

Related modules and libraries Urlib Urllib.parse

2, Nowapi Simple Introduction

Nowapi is a Data services company that provides a large number of data interfaces, and there's a lot of things that we can do for beginners of our learning, and some of them are free in a certain range, and it's enough for us to just touch on development practices. There are some examples of python2 programs, very not.

Official website: https://www.nowapi.com/

Similar companies in China:

Aggregated data: Https://www.juhe.cn/docs

Baidu Data Interface: http://apistore.baidu.com/

Speed data: https://www.jisuapi.com/

can provide a lot of data interface, provide free and charge data and other cooperation methods.

3, Nowapi Two-dimensional Code interface introduction

Generate two-dimensional code online Note: API URL can be used directly in the HTML IMG tag, if the data parameter is Chinese please urlencode (' Chinese ') Request example: Http://api.k780.com:88/?app=qr.get&data= Test&level=l&size=6 Note: If you have a huge amount of use please contact the website customer Service note Referer. Request method Get/post request urlhttp:http://api.k780.com:88https:https://sapi.k780.com request parameter type whether it is necessary to note that the data string is required to generate two-dimensional code inside for example: t EST level string No error correction levels < ' L ', ' M ', ' Q ', ' H ', default: L size number no size <1-20>, default: 6

4. Ideas

According to the interface document we can use post submission, and post in Python is mainly with the parameter submission here is mainly using the dictionary to implement the parameter combination, and the Urllib.parse module UrlEncode () method to implement the combination of parameters and URLs. Then access the full URL, get the request response and write to the file.

5. Source code

#/usr/bin/env python#_*_coding:utf-8_*_import jsonimport  urllibimport requestsimport   urllib.parseurl= ' http://api.k780.com:88 ' Def  msgdata (send_msg):   #定义一个简单的函数     msg = {}    msg[' app '] =  "Qr.get"      msg[' data '] = send_msg    msg[' level '] =  ' L '      msg["Size"] = 6    data = urllib.parse.urlencode (msg). Encode ("Utf-8")     response = urllib.request.urlopen (Url, data)      result = response.read ()     with open (send_msg+  "S.jpg",   "WB")  as  f:        f.write (Result) list2=[" Mysqldba "," Docker Ops development Engineer "," Cloud giants OpenStack "," Redis "," Centos "," MongoDB "," Swarm "]for   i in  list2:    msgdata (i) 

Examples of build results:

1. CentOS 2, Docker OPS engineer 3, MongoDB

650) this.width=650; "Src=" Https://s3.51cto.com/wyfs02/M00/8F/6B/wKiom1jdvPjjTEh0AAABFIwgT3M918.jpg-wh_ 500x0-wm_3-wmp_4-s_3857626093.jpg "style=" width:200px;height:200px "title=" centos.jpg "width=" "height=" 200 " Border= "0" hspace= "0" vspace= "0" alt= "wkiom1jdvpjjteh0aaabfiwgt3m918.jpg-wh_50"/>650) this.width=650; "Src=" Https://s2.51cto.com/wyfs02/M01/8F/69/wKioL1jdvPnDR7IKAAABXvcKe5o780.jpg-wh_500x0-wm_3-wmp_4-s_2861512833.jpg " Style= "width:200px;height:200px", "title=" Docker devops development engineer. jpg "width=" "height=", "border=", "0" hspace= "0" vspace= "0 "alt=" Wkiol1jdvpndr7ikaaabxvcke5o780.jpg-wh_50 "/>650) this.width=650; src=" Https://s2.51cto.com/wyfs02/M00/ 8f/69/wkiol1jdvpnxe_zfaaabfnqje-o995.jpg-wh_500x0-wm_3-wmp_4-s_4148601131.jpg "style=" width:200px;height:200px; " Title= "Mongodbs.jpg" width= "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiol1jdvpnxe_ Zfaaabfnqje-o995.jpg-wh_50 "/>

4, mysqldba                    5, redis                                 6, swarms

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/8F/6B/wKiom1jdvPqQGhcxAAABEsWLUNA688.jpg-wh_500x0-wm_ 3-wmp_4-s_1040980671.jpg "style=" width:200px;height:200px, "title=" mysqldbas.jpg "width=", "height=", "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiom1jdvpqqghcxaaabeswluna688.jpg-wh_50 "/>650) this.width=650;" Src= "https:// S1.51cto.com/wyfs02/m02/8f/69/wkiol1jdvpuracy7aaabhua1f0u991.jpg-wh_500x0-wm_3-wmp_4-s_4002560163.jpg "Style=" width:200px;height:200px, "title=" rediss.jpg "width=" "height=" "0" border= "0" hspace= "0" vspace= Wkiol1jdvpuracy7aaabhua1f0u991.jpg-wh_50 "/>650) this.width=650;" Src= "https://s1.51cto.com/wyfs02/M00/8F/6B/ Wkiom1jdvpuqrbl7aaabgwcrqwc035.jpg-wh_500x0-wm_3-wmp_4-s_3096795475.jpg "style=" width:200px;height:200px; "title = "Swarms.jpg" width= "height=" border= "0" hspace= "0" vspace= "0" alt= "wkiom1jdvpuqrbl7aaabgwcrqwc035.jpg-wh_ "/>

7. Cloud computing giant OpenStack

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/8F/69/wKioL1jdvPzBI2slAAABVCzURls603.jpg-wh_500x0-wm_ 3-wmp_4-s_4042483025.jpg "style=" width:200px;height:200px; "title=" cloud computing giant openstacks.jpg "width=" 200 "height=" Border= "0" hspace= "0" vspace= "0" alt= "wkiol1jdvpzbi2slaaabvczurls603.jpg-wh_50"/>

Summary and Analysis: The above two-dimensional code is can be used such as sweep scan the results of the function, the disadvantage is that the Chinese can not be recognized, the latter in the study of Chinese interpretation and processing

Python3 call Nowapi interface to implement the QR code generation tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.