From fc3f25cd5fd8778934a5ee51522bcf1a312d5f96 Mon Sep 17 00:00:00 2001 From: tsujp Date: Sun, 4 Feb 2018 21:55:59 +0900 Subject: [PATCH] Add Heroku instructions to sessions documentation --- readthedocs/extra/advanced-usage/.DS_Store | Bin 0 -> 6148 bytes readthedocs/extra/advanced-usage/sessions.rst | 50 ++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 readthedocs/extra/advanced-usage/.DS_Store diff --git a/readthedocs/extra/advanced-usage/.DS_Store b/readthedocs/extra/advanced-usage/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0= 3.8.2). Heroku uses +SQLite 3.7.9 which does not support `WITHOUT ROWID`. So, If you generated your +session file on a system with SQLite >= 3.8.2 your session file will not work +on Heroku's platform and will throw a corrupted schema error. + +There are multiple ways to solve this, the easiest of which is generating a +session file on your Heroku dyno itself. The most complicated is creating +a custom buildpack to install SQLite >= 3.8.2. + + +Generating Session File on a Heroku Dyno +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**Do not restart your application Dyno at any point prior to retrieving your +session file. Constantly creating new session files from Telegram's API will +result in a 24 hour rate limit ban** + +Due to Heroku's ephemeral filesystem all dynamically generated +files not part of your applications buildpack or codebase are destroyed upon +each restart. + +Using this scaffolded code we can start the authentication process: + + .. code-block:: python + + client = TelegramClient('login.session', api_id, api_hash, + update_workers = 1, spawn_read_thread = False) + client.start() + +At this point your Dyno will crash because you cannot access stdin. Open your +Dyno's control panel on the Heroku website and "run console" from the "More" +dropdown at the top right. Enter `bash` and wait for it to load. + +You will automatically be placed into your applications working directory. +So run your application `python app.py` and now you can complete the input +requests such as "what is your phone number" etc. + +Once you're successfully authenticated exit your application script with +CTRL + C and `ls` to confirm `login.session` exists in your current directory. +Now you can create a git repo on your account and commit `login.session` to +that repo. + +You cannot ssh into your Dyno instance because it has crashed, so unless you +programatically upload this file to a server host this is the only way to get +it off of your Dyno.