介面功能測試,python3 5

2021-09-08 16:39:28 字數 1926 閱讀 6771

閒來無事,把以前的**貼出來

)#return "請求成功,開始判斷響應狀態"

#requests_statuscode.text

else

:#return requests_statuscode

print

("請求失敗if內"

)except exception as e:

print

("請求失敗try內"

)#3try:

# a = datetime.datetime()

x = requests.post(url=self.url,json=self.data)

try:

a = x.text

with

open

(datetime.now(

).strftime(

'%y%m%d%h%m%s')+

'.txt'

,'w'

,encoding=

"utf-8"

)as f:

f.write(a)

except exception as e:

print

("寫入檔案有問題"

) a = x.json()[

"code"

]if a ==

1000

:print

("正常返回"

)elif a ==-1

:print

("系統繁忙"

)elif a ==

1001

:print

("partnerid無效"

)elif a ==

1002

:print

("ip白名單錯誤,禁止服務"

)elif a ==

1003

:print

("簽名錯誤"

)elif a ==

1004

:print

("缺少必要的引數"

)else

:print

("返回未知的錯誤"

)if __name__ ==

'__main__'

: the_url=

''#the_data=],"period": 9,"***": 0,"symptoms": "1001"}

the_data=],

'***':0

,'symptoms'

:1001

}#[27, 'post', '我方沒有的商品', 1, '[}]', 9, 1, 1001, '"code": 1000', '"data"!=none']

python 3 5 學習筆記

字串方法 msg this is message msg.title 首字母大寫 msg.lower 字串全部小寫 msg.upper 字串全部大寫 msg.rstrip 刪除字串前後的空格 msg.lstrip 刪除字串前面的空格 msg.strip 刪除字串後面的空格 str msg 將msg轉...

python 3 5 爬蟲日記2

from urllib import request 輸入正規表示式模組 import re page 1 url r request.request url r.add header user agent abc 讀取首頁原碼並命名為content content request.urlopen ...

Python 3 5 變數命名規範

為了避免編寫 時產生錯誤,也為了使寫出的 具有更好的可讀性,python中的變數應遵守以下命名規範 1.變數名只能包含字母 數字和下劃線。變數名不能以數字開頭,但可以使用字母或者下劃線開頭。2.不要使用python的保留關鍵字作為變數名。如class print等。3.變數名中不要包含空格,如需分隔...