国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用新浪微博api上傳圖片到微博示例

2020-02-23 05:04:27
字體:
來源:轉載
供稿:網友

代碼如下:
import urllib.parse,os.path,time,sys
from http.client import HTTPSConnection
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

#path
ospath=sys.path[0]
if len(ospath)!=3:
    ospath+='//'
ospath=ospath.replace('//','/')

#api
class Api:
    def sina(self,status,pic):
        fSize=os.path.getsize(pic)
        BOUNDARY="$-img-lufei-goodboy-$"
        CRLF='/r/n'
        data=[
            #token
            '--'+BOUNDARY,
            'Content-disposition: form-data; name="access_token"',
            '',
            'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',#你的access_token
            #status
            '--'+BOUNDARY,
            'Content-disposition: form-data; name="status"',
            '',
            status,
            #pic
            '--'+BOUNDARY,
            'Content-disposition: form-data; name="pic"; filename="q_17.jpg"',
            'Content-type: image/jpeg',
            ''
        ]
        #utf-8
        data=(CRLF.join(data)+CRLF).encode('utf-8')
        closing='/r/n--'+BOUNDARY+'--/r/n'
        sumlen=len(data)+len(closing)+fSize
        #----------------------------------------
        h=HTTPSConnection('upload.api.weibo.com')
        h.putrequest('POST','/2/statuses/upload.json')
        h.putheader('Content-type','multipart/form-data; boundary=%s' % BOUNDARY)
        h.putheader('Content-length',sumlen)
        h.endheaders()
        h.send(data)
        f=open(pic,'rb')
        while True:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 读书| 法库县| 凭祥市| 大余县| 亳州市| 曲麻莱县| 仁寿县| 玛纳斯县| 宁德市| 龙口市| 临汾市| 乐山市| 天等县| 靖江市| 达尔| 安多县| 肇庆市| 额济纳旗| 元氏县| 长武县| 永州市| 西乌| 潢川县| 临安市| 绿春县| 宜川县| 墨玉县| 高要市| 平和县| 宜都市| 永济市| 平顺县| 阿合奇县| 漠河县| 监利县| 沅陵县| 杭锦旗| 禄丰县| 哈巴河县| 吴川市| 开江县|