根据抓来的数据包 怎么用python 实现图片上传

moble 发布于 2014/02/19 19:24
阅读 727
收藏 0

def upload():

    host = "message.aliexpress.com"
    url = "http://message.aliexpress.com/message/upload.html"
    post_data ={'name':'2.jpg','scene':'aeMessageCenterImageRule','file':open("2.jpg",'rb').read()}
    headers = {'Host':'message.aliexpress.com','User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0',
               'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
               'Accept-Language':'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
               'Accept-Encoding':'gzip, deflate',
               'X-Requested-With':'XMLHttpRequest',
               'Referer':'http://message.aliexpress.com/message/messagecenter_detail.htm?relationId=146379278&from=query&q=chun',
               'Content-Length':'781349',
               'Content-Type':'multipart/form-data;',
               'Cookie':'ali_intl_firstIn=n; ali_apache_id=115.239.60.1.1392792028256.387934.3; ali_apache_track=mt=3|ms=|mid=cn1001582497; xman_us_f=x_l=1&x_locale=en_US&no_popup_today=n&x_user=CN|jone|an|cnfm|202157644&x_site=glo&x_regin=CN&last_popup_time=1392792123044; xman_f=0o8oFRaJxjots+j5JORAVYdSqOaDYaIPkI96oUCjbXwucyfS6NyW/CC6EvFXu9WQnX8frZwqRI1GAGlTbZA3nUrhSQ0JzDPqRLNOnjmazJIh3uKUmiS9S/fPsww5sO1CXckVoWLo/W4/m8/ja1eX+WTt9zeyaxIUsSKF3wN5Mbo74SOZJuvQIy/Rtz/EVTVK2PKGpG+CJb8qjzQrbRDPr3OxEn9dtMLQsBIZ6EqriiB60gBlXn/vMt1UcyfwYSjEtZICI4N1zXD4Qel7Dikgui009WVEdhnx6ED1wNoATfB+2OEynr3h+v3ouPMyCrnA; ali_beacon_id=115.239.60.1.1392792028256.387934.3; aep_usuc_f=c_tp=USD; intl_common_forever=VBNiYNjFTezJC4HBakE7lylP4K0yNCxjAWHjxJ/fYJZTIwcf4p09gQ==; CoreID6=n; cna=SECLC2e+hjACAQE873P5b8fa; __utma=3375712.1912839433.1392796230.1392796230.1392796230.1; __utmz=3375712.1392796230.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); acs_usuc_t=acs_rt=cbdfccf06f614610b2460c37ae6e5bec; xman_us_t=x_lid=cn1001582497&sign=y&x_user=pFUOnt8xhvQFyQI1pHLLsKjs6oDguU7MvSuBxHnR7H0=&need_popup=y; intl_locale=en_US; __utmc=3375712; JSESSIONID=31723D45E76924CC72DCBE752FB401AC; ali_apache_tracktmp=W_signed=Y; xman_t=Y9pKcPz4pEP46Q5afZ6N//eqVM+jHMda2//SSGJC/8xK4ITVWadg+4vKot7Go9e5TP/BPe+pOycQg1w/ZlCCDPQqo1t3f56YGe7vTfeGb1Ao0IbXAm7ckQARdS6MtwfYZx04uvNrecj/gYMZic2ObR/piG/n/n+1Mh6C0BQ9MGigQN8a16Wv7gE9Q1DEk+kf1AR2Ls6GAup8ydbA08ZGfFhx/nphHLGeUldph1OxdcP0Zm6jLozCwKxsEmlyGWuYBnSloJ/cwEf8hMFmEmltewhi88y5GEqSjxObnGYP6er6HMRrcvBc5/NPKOxaYKhB4dxYg5dXFpqV2TEbTsyQiX5Q4zOJ5Iki/26flgYTlRJNRPAiHelH7IKS96PxVxTKYuSAHg2aXdK4p1EU0zOEpMwOtDxNw65VGkRUR9SfXT19wP3i3IVadKGsQVaEdsst+prUY4S7mZ4/tdy2ss3avtkeIE+TBCTk/ONqEEAN//D4nJXdX913Y5ayo5g5R++9p6mjeLJM2mThV5K5oojEsduJcF0xQj0oTwjoTvNkqSCClF0/cxpPtfBqDqt4tu/Kf8cPVhECcjqrm7YOmZsnCj0Oe51l6O5EjFJb/tEjGJXRzEDxs+nEfeO05bf0B1xoc99yXsNBFpZQoXz1fkp4ObJI4XjwU/i+08kBLjFfmFiXl9WKZbv1Wg==; acs_t=aJhm/Vj7jY7V+haR+32Hw1gfzf+ayv/o4Vx0P+1Zl5pWJoUV48Xfw9WqjaEg3nkd',
               'Connection':'keep-alive',
               'Pragma':'no-cache',
               'Cache-Control':'no-cache'}
    
    h = httplib.HTTPConnection(host,'80')    
    request = h.request('post',url,headers=headers,body=urllib.urlencode(post_data))   
    
    #print urllib2.urlopen(request).read()
if __name__=='__main__':
    upload()
   
加载中
返回顶部
顶部