介面和資料庫

2021-09-12 06:11:51 字數 2240 閱讀 6201

import base64

import json

import requests

defdopost

(url, params)

: headers =

response = requests.request(

"post"

, url, data=json.dumps(params)

, headers=headers)

status_code = response.status_code

if status_code ==

200:

return json.loads(

str(response.content,

"utf-8"))

else

:raise exception(

"介面請求失敗\n"

+"狀態碼:"

+str

(status_code)

+"\n"

+ response.text)

defdopostbase64decode

(url, params)

: headers =

response_base64 = requests.post(url, data=json.dumps(params)

, headers=headers)

status_code = response_base64.status_code

if status_code ==

200:

response =

str(base64.b64decode(response_base64.content)

,'utf-8'

)return json.loads(response)

else

:raise exception(

"介面請求失敗\n"

+"狀態碼:"

+str

(status_code)

+"\n"

+ response_base64.text)

defdopostbase64decode_str

(url, params)

: headers =

response_base64 = requests.post(url, data=json.dumps(params)

, headers=headers)

status_code = response_base64.status_code

if status_code ==

200:

return

str(base64.b64decode(response_base64.content)

,'utf-8'

)else

:raise exception(

"介面請求失敗\n"

+"狀態碼:"

+str

(status_code)

+"\n"

+ response_base64.text)

def

db_query

(db, sql)

:# 連線資料庫

global db_info

db_info = db_dic[db]

conn = pymysql.connect(host=db_info[0]

, user=db_info[1]

, password=db_info[2]

, db=db_info[3]

, port=db_info[4]

)# db:庫名

try:

# 設定游標型別,預設游標型別為元祖形式

# 將游標型別設定為字典形式

cur = conn.cursor(cursor=pymysql.cursors.dictcursor)

cur.execute(sql)

# 將表中所有資料以字典形式輸出

ret = cur.fetchall(

)# print(ret)

# 提交

conn.commit(

)# 關閉指標物件

cur.close(

)return ret

finally

:# 關閉連線物件

conn.close(

)

資料庫和資料庫物件

系統資料庫是指安裝完mysql伺服器後,會附帶的一些資料庫,系統資料庫會記錄一些必需的資訊,使用者不能直接修改這些系統資料庫。各個系統資料庫的作用如下 information schema 主要儲存系統中的一些資料庫物件資訊,如使用者表資訊 列資訊 許可權資訊 字符集資訊和分割槽資訊等。perfor...

資料庫和資料庫例項

以前一直把資料庫和資料庫例項弄混淆,最近讀 mysql 技術內幕 innodb 儲存引擎 得到了答案。資料庫 物理作業系統檔案或其他形式檔案型別的集合。在mysql資料庫中,資料庫檔案可以是frm myd myi ibd結尾的檔案。例項 mysql資料庫和後台執行緒以及乙個共享記憶體區組成。共享記憶...

oracle資料庫和資料庫例項

oracle中的資料庫和資料庫例項 oracle的體系結構簡單來分的話,分成2部分 資料庫 database 和資料庫例項 database instance 這是個容易搞糊塗的概念,在sql server裡面,你在你的機器上安裝一次sql server,那麼你就等於安裝了一次資料庫例項,在這個例項...