A
A
Abdulah2018-06-01 07:36:08
Python
Abdulah, 2018-06-01 07:36:08

I can't get a JSON response from the site via python script?

Good afternoon!
Faced such a problem, there is a mailer on Roundcube, which I access through the Web face and try to download mail using a Python script.
There is a URL (example): mail.mail.com/?_task=mail&_action=list&_mbox=INBOX...
When accessed on other Roundcube servers, I get a dictionary in response:

{"action":"list","unlock":"loading1527827018822","env":{"mailbox":"INBOX","pagesize":50,"current_page":1,"delimiter":".","threading":false,"threads":true,"reply_all_mode":0,"layout":"list","drafts_mailbox":"Drafts","trash_mailbox":"Trash","junk_mailbox":"Junk","read_when_deleted":true,"display_next":true,"messagecount":146,"pagecount":3,"exists":146,"multifolder_listing":false},"exec":"this.set_pagetitle(\"MAI MAIL.COM");\nthis.set_unread_count(\"INBOX\",0,true,\"\");\nthis.set_rowcount(\"blabla 146\",\"INBOX\");\nthis.set_message_coltypes([\"threads\",\"subject\",\"status\",\"fromto\",\"date\",\"size\",\"flag\",\"attachment\"],null,\"from\");\nthis.add_message_row(147,{\"subject\

This dictionary contains email UID data.
As for the desired server, if you follow the link:
mail.mail.com/?_task=mail&_action=list&_mbox=INBOX...
Then in response I get the following:
5b10cbc9a9836547936448.png
But if I look at the response in the element inspector, then I see there a JSON response from the server with the desired me information.
5b10cd15571cf900979329.png
Using a Python script, I'm trying to make the following request:
responseData = session.get("http://www.mail.mail.com/?_task=mail&_action=list&_refresh=1&_mbox=" + remote + "&_page=1&_remote=1&_unlock=loading" + unix_time_conv("UniTodey") + "&_=" + unix_time_conv(3) + "", cookies=responseAuth.cookies.get_dict(), headers=headers, proxies=proxies)
print(responseData.json())

And in response I get this:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I can't figure out how to get a JSON response from the server with the information I need.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2018-06-01
@immaculate

When you open the url in a browser, RoundCube understands that you are authorized by looking at the request headers (I don't know what exactly RoundCube is using, perhaps a cookie or a parameter in the URL).
If you need to open a url from Python, then most likely you first need to perform an authentication request or pass an API key in the request (again, you need to look at the RoundCube documentation).
It is also worth making sure that all request headers from Python match the headers transmitted by the browser (for example, header Accept).

V
Vladimir, 2018-06-01
@vintello

print(responseData.text)

everything should be written there.

M
marataziat, 2018-06-02
@marataziat

Well, there is a ready-made API, why all these perversions?
https://github.com/roundcube/roundcubemail/wiki/Pl...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question