2 moblerenzhe moblerenzhe 于 2014.02.21 10:14 提问

模拟浏览器实现速卖通后台站内信的发布 其中的图片上传问题

import urllib
import urllib2
import httplib
import httplib2
import sys
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 = {
'POST':'/message/upload.html',
'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.6,en;q=0.4',
'Accept-Encoding':'gzip,deflate,sdch',
'X-Requested-With':'XMLHttpRequest',
'Referer':'http://message.aliexpress.com/message/messagecenter_detail.htm?relation_id=155163640&is_success=true&list_page=1',
'Content-Length':'781336',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36',
'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryty3Cn7xBkficw5Xh',
'Cookie':'ali_apache_id=220.185.112.110.1375686730944.564830.6; cna=2wVlClYoa1YCAXroSfTXxNZW; JSESSIONID=D3626C4971178104DCD1F905751CE6F7; acs_usuc_t=acs_rt=8c2e84d173dc4781a6b0934c09502280; CoreID6=n; xman_us_t=x_lid=cn1510723399&sign=y&x_user=kRppPP4fesSiRGffLoBlMpv7o07+Kkb78Z2wZeNkswY=&need_popup=y; xman_f=wCDfteJSu3kaFTp1nvSSQg5qV1E0wHz7JLUHh6TaoW1YXX+vrDrp1H19fRU4Wq8bnINRL6XuyifCDq5qTabwlep4JHQs4C5qr5V+yq9GJ4EAzHkJfPZVcTvmn6t5sYY0P0X1E5jqZx0tkCwmzbOiMaAkj9xMykks3MtLI5/0lARJ9GN5L1uL/6iBokOTFqIPno8iazZFzA34lkNBtMMA75QCHaa5UHYwJLfnBgeKwebwlOKgk6/6q7Hr8NcqwwmSCiJamaFiQFyMK8nm7M3wQYs7HKhQpt3C+ujfZbiYHpjTRyWB1nc7ufzRonhq9w5A; xman_t=yO4z+8+jYMbMHyt862ieSIkbumqcF3t50vVZeaoZBaVtoUrrTgXqabpIVBmiWiCyA8o5W05O1LZkH0hahpR6DupXxS5MCd7q/tERS7DRbWuWEWeY6HZqIhXKKRmxEmK+eRf/zvenlPOvxfWQGvU6sBuSsL/0tJRQ8XY+TjrPBE5CJEI+SSorjy2+mGDlggX0o8tI6vQL2BVlS5ttSLnHWPjSWi//qlKoZCiRfuaDThytJgLMJi+8AGco/gZsmQ8PQpq9hjztK33471Yst2342avfDVo+833PoEho1mtpiMyGduzQ3NrmgXAQxX/F6PsPLw7hzOjPLhwisyPByy1BXMKkes7zR1ddx1zfczGLsEK1OobejdPV6T8Jpy9UIURWMiZFkX4ysbxK25eXz0y64YLmih00kkls73pde8OEB+Br1Zc2RnOwVXij4sT8pf4PoSK5xx6yKF6VWm4VWmbE+S/jm/oDYtkCV4LAivP1KdhT55UXkiEb6E8GyW2oDqzdn4D2uzH9FvhXNlT3l28+B5lMvdrEp30rbCeuICK8TQDlWm0am2nu6ZJv60S/9au9xpOyTWUCkazLOi/LgW1570eDaIwU+hXTsUlTbGdxHecPlHnGYeN/c5HMt8zgJ+6cxqWO8Wr7oe/uQuK/CGJexhSWNKp62GJ6dNvJL3GeYpE=; xman_us_f=x_l=0&x_locale=en_US&no_popup_today=n&x_user=CN|moble|an|cnfm|220745672&x_regin=CN&x_site=glo&last_popup_time=1392912236903; aep_usuc_f=c_tp=USD; intl_locale=en_US; intl_common_forever=ywVDXqT8WtqXnjCXbDyofdaG1iBpFip86604ioncBmGqqDZjEV+25g==; __utma=3375712.644895726.1375686731.1378089439.1392912169.5; __utmb=3375712.2.10.1392912169; __utmc=3375712; __utmz=3375712.1392912169.5.5.utmcsr=baidu|utmccn=(organic)|utmcmd=organic|utmctr=%E9%80%9F%E5%8D%96%E9%80%9A%E7%99%BB%E9%99%86; JSESSIONID=D3626C4971178104DCD1F905751CE6F7; ali_apache_track=mt=3|ms=|mid=cn1510723399; ali_apache_tracktmp=W_signed=Y; acs_t=dTqZX+5kbicC57s9wW3ycJGnZ8tmsXEjkbooBi9eIw4eo7fUN6+oWIDWQHE1OuQV',
'Connection':'keep-alive'}

h = httplib.HTTPConnection(host,'80')    
h.request('POST',url,headers=headers,body=urllib.urlencode(post_data))   
t1 = h.getresponse()
print t1.read()
print t1.reason
print t1.status

if name=='__main__':

upload()

根据上传过程中抓到的数据包 写下的代码 再浏览器中上传图片的过程中会返回一个 图片的网络地址 程序运行结果 为 ?\000\000\000\000\000\000玍J蜲IU睷2T?\000?跅\000\000\000
OK
200 返回码是200 ok 为什么没有返回图片路径 求助

Csdn user default icon
上传中...
上传图片
插入图片