Created
September 9, 2019 12:31
-
-
Save FRex/51f73862efd916221a5df6b6baca9db1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get = (sum and __import__ or require)('requests').get | |
| url = "http://translate.googleapis.com/translate_a/single" | |
| params = {} | |
| params['client'] = 'gtx' | |
| params['sl'] = 'en' | |
| params['tl'] = 'de' | |
| params['dt'] = 't' | |
| params['q'] = 'hello!' | |
| params['params'] = params | |
| r = get(url, params) | |
| print(r.text) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tricks/kludges used:
get{url, params=params}that I proposed in JakobGreen/lua-requests/issues/14 and that later got added since it'd fail as Python.params['params'] = paramsbecause in Lua requests without using{}the second argument is a table of all params (GET params, POST data, etc.), not table of GET params themselves.?:tertiary operator-like behavior usingandandorwhich works in both, to pick right module importing function since only in Pythonsumis a global function (truthy), in Lua it doesn't exist so it's nil - falsy, but okay and not an exception or error to access.__import__function instead of theimportstatement.require 'requests'since in Python parens on function calls are mandatory unlike Lua where they can be skipped for single arg call with new table or literal string.params.qinstead ofparams['q']since it doesn't work in Python (it's attribute access, not shortcut for access by string literal key).localwould make it fail as Python.