代码如下:
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:
新闻热点
疑难解答