diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-11 18:16:31 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-11 18:16:31 +0100 |
commit | 5d5b7124582d897eacf15defc50bafa7d3aca0fa (patch) | |
tree | 04d2a16be8267a868ffcdb1522afee5118f0592a | |
parent | little test cases (diff) | |
download | pyload-5d5b7124582d897eacf15defc50bafa7d3aca0fa.tar.xz |
closed #455
-rw-r--r-- | docs/access_api.rst | 25 | ||||
-rw-r--r-- | module/plugins/hooks/CaptchaTrader.py | 14 |
2 files changed, 31 insertions, 8 deletions
diff --git a/docs/access_api.rst b/docs/access_api.rst index 11955c76d..df69da8b2 100644 --- a/docs/access_api.rst +++ b/docs/access_api.rst @@ -95,10 +95,27 @@ Calling Methods In general you can use any method listed at the :class:`Api <module.Api.Api>` documentation, which is also available to the thriftbackend. -Access works simply via ``http://pyload-core/api/methodName``. To pass arguments you have 2 choices. +Access works simply via ``http://pyload-core/api/methodName``, where ``pyload-core`` is the ip address +or hostname including the webinterface port. By default on local access this would be `localhost:8000`. + +The return value will be formatted in JSON, complex data types as dictionaries. +As mentionted above for a documentation about the return types look at the thrift specification file :file:`module/remote/thriftbackend/pyload.thrift`. + +================== +Passing parameters +================== + +To pass arguments you have two choices. Either use positional arguments, eg ``http://pyload-core/api/getFileData/1``, where 1 is the FileID, or use keyword arguments supplied via GET or POST ``http://pyload-core/api/getFileData?fid=1``. You can find the argument names in the :class:`Api <module.Api.Api>` -documentation. If one of the argument is a container data type, e.g a list, format it as json/python first and urlencode it before submitting. +documentation. -The return value will be formatted in JSON, complex data types as dictionaries. -As mentionted above for a documentation about the return types look at the thrift specification file :file:`module/remote/thriftbackend/pyload.thrift`.
\ No newline at end of file +It is important that *all* arguments are in JSON format. So ``http://pyload-core/api/getFileData/1`` is valid because +1 represents an integer in json format. On the other hand if the method is expecting strings, this would be correct: +``http://pyload-core/api/getUserData/"username"/"password"``. + +Strings are wrapped in double qoutes, because `"username"` represents a string in json format. It's not limited to strings and intergers, +every container type like lists and dicts are possible. You usually don't have to convert them. just use a json encoder before using them +in the HTTP request. + +Please note that the data have to be urlencoded at last. (Most libaries will do that automatically)
\ No newline at end of file diff --git a/module/plugins/hooks/CaptchaTrader.py b/module/plugins/hooks/CaptchaTrader.py index a0e8a0453..889eb83c0 100644 --- a/module/plugins/hooks/CaptchaTrader.py +++ b/module/plugins/hooks/CaptchaTrader.py @@ -25,6 +25,7 @@ from thread import start_new_thread from pycurl import FORM_FILE, LOW_SPEED_TIME from module.network.RequestFactory import getURL, getRequest +from module.network.HTTPRequest import BadHeader from module.plugins.Hook import Hook @@ -105,13 +106,18 @@ class CaptchaTrader(Hook): return ticket, result def respond(self, ticket, success): - json = getURL(CaptchaTrader.RESPOND_URL, post={"is_correct": 1 if success else 0, + try: + json = getURL(CaptchaTrader.RESPOND_URL, post={"is_correct": 1 if success else 0, "username": self.getConfig("username"), "password": self.getConfig("passkey"), "ticket": ticket}) - response = loads(json) - if response[0] < 0: - raise CaptchaTraderException(response[1]) + + response = loads(json) + if response[0] < 0: + raise CaptchaTraderException(response[1]) + + except BadHeader, e: + self.logError(_("Could not send response."), str(e)) def newCaptchaTask(self, task): if not task.isTextual(): |