PyntoR Posted February 3, 2014 Report Share Posted February 3, 2014 I'm trying to add a torrent with uTorrent web api, in Python using Requests library, but this error is returned: Error - torrent file content not supplied in form parameterimport requests, reUTORRENT_URL = 'http://%s:%s/gui/' % ('localhost', '55655')UTORRENT_URL_TOKEN = '%stoken.html' % UTORRENT_URLREGEX_UTORRENT_TOKEN = r'<div[^>]*id=[\"\']token[\"\'][^>]*>([^<]*)</div>'auth = requests.auth.HTTPBasicAuth('x', 'x')headers = {'content-type': 'application/json'}r = requests.get(UTORRENT_URL_TOKEN, auth=auth, headers=headers)token = re.search(REGEX_UTORRENT_TOKEN, r.text).group(1)guid = r.cookies['GUID']cookies = dict(GUID = guid)headers = {'content-type': 'multipart/form-data'}params = {'action':'add-file','token': token}files = {'torrent_file': open('C:\\x.torrent', 'rb').read()}r = requests.post(UTORRENT_URL, auth=auth, cookies=cookies, headers=headers, params=params, files=files)print r.json() Link to comment Share on other sites More sharing options...
PyntoR Posted February 18, 2014 Author Report Share Posted February 18, 2014 Ok, the problem was setting the headers. Removing them and it finally works!import requestsimport reUTORRENT_URL = 'http://%s:%s/gui/' % ('192.168.1.80', '55655')UTORRENT_URL_TOKEN = '%stoken.html' % UTORRENT_URLREGEX_UTORRENT_TOKEN = r'<div[^>]*id=[\"\']token[\"\'][^>]*>([^<]*)</div>'auth = requests.auth.HTTPBasicAuth('x', 'x')r = requests.get(UTORRENT_URL_TOKEN, auth=auth)token = re.search(REGEX_UTORRENT_TOKEN, r.text).group(1)guid = r.cookies['GUID']cookies = dict(GUID = guid)params = {'action':'add-file','token': token}files = {'torrent_file': open('C:\\x.torrent', 'rb')}r = requests.post(url=UTORRENT_URL, auth=auth, cookies=cookies, params=params, files=files) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.