Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload and download private server with Python SDK

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to upload and download Python SDK private server". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Write Python SDK code

Project catalogue structure

├──── easyhttp / / SDK directory │ ├── _ _ init__.py │ ├── https.py / / http utility class ├── tests / / unit test directory │ ├── _ _ init__.py │ ├── test_https.py / / http unit test ├── README.md ├── requirements.txt / / dependency package └── setup.py / / setuptools installation

Requirements.txt

Requests==2.24.0

Https.py

#-*-coding:utf8-*-"@ Project: easyhttp@File: https.py@Version: v1.0.0@Time: 2020-6-24 17:22@Author: guodong.li@Description: http" from typing import Optionalimport requestsimport loggingfrom requestsimport Responselogging.basicConfig (format='% (asctime) s -% (pathname) s [line:% (lineno) d] -% (levelname) s:% (message) s' Level=logging.DEBUG) class HttpUtils: headers = {"Content-Type": "application/json"} # http://10.193.199.44:5610/api/v1/manual/sleep?time=0 @ staticmethod def base_get (base_path: str='', detail_path: str='' Params: Optional [dict] = None)-> Response: "GET request: param base_path: domain name: param detail_path: interface details: param params: parameter: return:" logging.info ("request method: GET, request url:% s, request parameter:% s"% (base_path + detail_path) Params) response = requests.get (base_path + detail_path, params=params) logging.info ("request method: GET, request url:% s, request parameter:% s, result:% s"% (base_path + detail_path, params, response) return response @ classmethod def base_post (cls, base_path: str='', detail_path: str='' Params: Optional [dict] = None)-> Response: "POST request: param cls:: param base_path: domain name: param detail_path: interface details: param params: parameter: return:" logging.info ("request method: POST, request url:% s Request parameter:% s "% (base_path + detail_path, params) response = requests.post (base_path + detail_path, data=params, headers=cls.headers) logging.info (" request method: POST, request url:% s, request parameter:% s, result:% s "% (base_path + detail_path, params, response)) return response

Test_https.py

Import requestsimport loggingfrom easyhttp.https import HttpUtilslogging.basicConfig (format='% (asctime) s -% (pathname) s [line:% (lineno) d] -% (levelname) s:% (message) slots, level=logging.DEBUG) r = requests.get ("http://xxx.xxx.xxx.xxx:5610/api/v1/manual/sleep?time=0")logging.info(r) # logging.info (type (r)) # logging.info (r.status_code) # 200

After the code is written, it is packaged and uploaded to the private server.

Package and upload private server

Install the twine package

Pip install twine

Write the build tool setup.py for packaging

#-*-coding:utf8-*-"@ author: guodong.li@email: liguodongiot@163.com@time: 2019-7-31 14:04@file: setup.py@desc:" # introduce the module from setuptools import setup that builds the package information Find_packagestry: # for pip > = 10 from pip._internal.req import parse_requirements from pip._internal.network.session import PipSessionexcept ImportError: # for pip > > from pai.utils.https import HttpUtils > > import logging > > logging.basicConfig (format='% (asctime) s -% (pathname) s [line:% (lineno) d] -% (levelname) s:% (message) s' Level=logging.INFO) > r = requests.get ("http://10.xxx.xxx.xxx:5610/api/v1/manual/sleep?time=0")2020-07-02 11 root/python/20200702/venv/lib/python3.7/site-packages/urllib3/connectionpool.py 31requests.get 50903-/ root/python/20200702/venv/lib/python3.7/site-packages/urllib3/connectionpool.py [line:230]-DEBUG: Starting new HTTP connection (1): 10.xxx.xxx.xxx:56102020-07-02 11V 31v 51065-/ root/python/20200702/venv/lib / python3.7/site-packages/urllib3/connectionpool.py [line:442]-DEBUG: http://10.xxx.xxx.xxx:5610 "GET / api/v1/manual/sleep?time=0 HTTP/1.1" 200 None > logging.info (r) # 2020-07-02 11Groupe 32purl 15420-[line:1]-INFO: > logging.info (type (r)) # 2020-07-02 11Fri 3227371-[line:1]-INFO: > Logging.info (r.status_code) # 2002020-07-02 11 line:1-[line:1]-INFO: 200How does Python SDK upload and download private servers? that's all. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 263

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report