国产探花免费观看_亚洲丰满少妇自慰呻吟_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:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 迁安市| 嘉鱼县| 启东市| 抚宁县| 金阳县| 九寨沟县| 正定县| 奉新县| 毕节市| 五峰| 汾阳市| 长葛市| 大邑县| 西宁市| 杂多县| 云林县| 比如县| 年辖:市辖区| 吴川市| 阿巴嘎旗| 乌什县| 合肥市| 裕民县| 来安县| 揭东县| 读书| 瓦房店市| 浙江省| 同江市| 安图县| 武夷山市| 鹤山市| 延吉市| 桦甸市| 阿拉善盟| 罗平县| 原平市| 东阳市| 舒城县| 泰顺县| 宁城县|