CentOS6.檢視 Python中變數的資訊(名稱型別內容等)
阿新 • • 發佈:2018-12-26
ZC:環境:CentOS6、pycharm-community-2018.3.2.tar.gz
ZC:是在 使用 微信 的 “5.1 新建臨時素材”,跑 media_upload__test.py 時用到的
ZC:用下面的 方式 變數postData,貌似 還是並不能很直觀的 看到它的2進位制資料,於是 還是 抓包 一起參照來看
ZC:注意,我把下面的 https的請求 改成了 http的請求,居然也成功了... 這樣抓包 就能看到明文的通訊過程了。本來我只是 想著 看看 傳送的請求資料包的格式,沒指望 請求能真的成功,當然 能成功最好...
1、程式碼:(media_upload__test.py)
# -*- coding: utf-8 -*- # filename: media.py from basic import Basic import urllib2 import poster.encode from poster.streaminghttp import register_openers class Media(object): def __init__(self): register_openers() def uplaod(self, accessToken, filePath, mediaType): openFile= open(filePath, "rb") param = {'media': openFile} postData, postHeaders = poster.encode.multipart_encode(param) #postUrl = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s" % (accessToken, mediaType) postUrl = "http://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s" % (accessToken, mediaType) request = urllib2.Request(postUrl, postData, postHeaders) #urlResp = urllib2.urlopen(request) #print urlResp.read() mystr = urllib2.urlopen(request).read() print (mystr) print (postData) print (postHeaders) print (postUrl) print (request.header_items())# ZC:這裡可以打印出 HTTP發出請求的頭資訊 print (request.data) print (param) if __name__ == '__main__': myMedia = Media() accessToken = Basic().get_access_token() filePath = "/home/33/web.py-0.37/10.jpg" #filePath = "E:/ZC__Self/10.jpg" mediaType = "image" myMedia.uplaod(accessToken, filePath, mediaType)
1.1、利用poster模組發一個post檔案請求,如何獲取發出請求的頭資訊?(高分)-CSDN論壇.html(https://bbs.csdn.net/topics/380030808)
request.headers()方法也可以獲取一個字典型別的頭資訊
1.2、Python中利用urllib2使用POST方式上傳檔案 - 天外飛仙丶 - 部落格園.html(https://www.cnblogs.com/yu-zhang/p/3643528.html)
2、pycharm下如何檢視python的變數型別和變數內容 - STHSF的地盤 - CSDN部落格.html(https://blog.csdn.net/u013041398/article/details/53485104)
3、
4、
5、