Horhik / Instagram2Fedi

Python script for crossposting from Instagram to Mastodon or Pixelfed
GNU General Public License v3.0
91 stars 7 forks source link

Heroku Error #6

Closed condr-at closed 2 years ago

condr-at commented 2 years ago

Here, what logs look like after release:

2022-05-12T20:31:33.561030+00:00 heroku[web.1]: Starting process with command `python /app/src/main.py`
2022-05-12T20:31:34.577497+00:00 app[web.1]: ['/app/src/main.py', 'python', '/app/src/main.py']
2022-05-12T20:31:34.577514+00:00 app[web.1]: ARGUMENTS
2022-05-12T20:31:34.577514+00:00 app[web.1]: ❗ -> Wrong Argument Name!...
2022-05-12T20:31:34.577514+00:00 app[web.1]: 
2022-05-12T20:31:34.577515+00:00 app[web.1]: 2022-05-12 20:31:34.576732
2022-05-12T20:31:34.577524+00:00 app[web.1]: {'instance': None, 'instagram-user': None, 'token': None, 'check-interval': 3600, 'post-interval': 3600, 'fetch-count': 10, 'carousel-limit': 4, 'use-docker': True}
2022-05-12T20:31:34.577525+00:00 app[web.1]: 🚀 > Connecting to Mastodon/Pixelfed...
2022-05-12T20:31:34.577525+00:00 app[web.1]: 
2022-05-12T20:31:34.577525+00:00 app[web.1]: 2022-05-12 20:31:34.576844
2022-05-12T20:31:34.577525+00:00 app[web.1]: 🚀 > Connecting to Instagram...
2022-05-12T20:31:34.577526+00:00 app[web.1]: 
2022-05-12T20:31:34.577526+00:00 app[web.1]: 2022-05-12 20:31:34.577390
2022-05-12T20:31:34.577531+00:00 app[web.1]: Traceback (most recent call last):
2022-05-12T20:31:34.577532+00:00 app[web.1]: File "/app/src/main.py", line 66, in <module>
2022-05-12T20:31:34.577645+00:00 app[web.1]: get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user)
2022-05-12T20:31:34.577647+00:00 app[web.1]: File "/app/src/network.py", line 77, in get_new_posts
2022-05-12T20:31:34.577744+00:00 app[web.1]: profile = get_instagram_user(fetched_user)
2022-05-12T20:31:34.577746+00:00 app[web.1]: File "/app/src/network.py", line 18, in get_instagram_user
2022-05-12T20:31:34.577817+00:00 app[web.1]: return Profile.from_username(L.context, user)
2022-05-12T20:31:34.577819+00:00 app[web.1]: File "/usr/local/lib/python3.9/site-packages/instaloader/structures.py", line 691, in from_username
2022-05-12T20:31:34.578018+00:00 app[web.1]: profile = cls(context, {'username': username.lower()})
2022-05-12T20:31:34.578033+00:00 app[web.1]: AttributeError: 'NoneType' object has no attribute 'lower'
2022-05-12T20:31:34.742759+00:00 heroku[web.1]: Process exited with status 1
2022-05-12T20:31:34.852473+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-12T20:31:34.889132+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-12T20:31:46.309290+00:00 heroku[web.1]: Starting process with command `python /app/src/main.py`
2022-05-12T20:31:47.285607+00:00 app[web.1]: ['/app/src/main.py', 'python', '/app/src/main.py']
2022-05-12T20:31:47.285619+00:00 app[web.1]: ARGUMENTS
2022-05-12T20:31:47.285620+00:00 app[web.1]: ❗ -> Wrong Argument Name!...
2022-05-12T20:31:47.285620+00:00 app[web.1]: 
2022-05-12T20:31:47.285620+00:00 app[web.1]: 2022-05-12 20:31:47.284780
2022-05-12T20:31:47.286053+00:00 app[web.1]: {'instance': None, 'instagram-user': None, 'token': None, 'check-interval': 3600, 'post-interval': 3600, 'fetch-count': 10, 'carousel-limit': 4, 'use-docker': True}
2022-05-12T20:31:47.286054+00:00 app[web.1]: 🚀 > Connecting to Mastodon/Pixelfed...
2022-05-12T20:31:47.286054+00:00 app[web.1]: 
2022-05-12T20:31:47.286054+00:00 app[web.1]: 2022-05-12 20:31:47.284902
2022-05-12T20:31:47.286055+00:00 app[web.1]: 🚀 > Connecting to Instagram...
2022-05-12T20:31:47.286055+00:00 app[web.1]: 
2022-05-12T20:31:47.286055+00:00 app[web.1]: 2022-05-12 20:31:47.285511
2022-05-12T20:31:47.286063+00:00 app[web.1]: Traceback (most recent call last):
2022-05-12T20:31:47.286063+00:00 app[web.1]: File "/app/src/main.py", line 66, in <module>
2022-05-12T20:31:47.286064+00:00 app[web.1]: get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user)
2022-05-12T20:31:47.286064+00:00 app[web.1]: File "/app/src/network.py", line 77, in get_new_posts
2022-05-12T20:31:47.286064+00:00 app[web.1]: profile = get_instagram_user(fetched_user)
2022-05-12T20:31:47.286065+00:00 app[web.1]: File "/app/src/network.py", line 18, in get_instagram_user
2022-05-12T20:31:47.286065+00:00 app[web.1]: return Profile.from_username(L.context, user)
2022-05-12T20:31:47.286067+00:00 app[web.1]: File "/usr/local/lib/python3.9/site-packages/instaloader/structures.py", line 691, in from_username
2022-05-12T20:31:47.286093+00:00 app[web.1]: profile = cls(context, {'username': username.lower()})
2022-05-12T20:31:47.286114+00:00 app[web.1]: AttributeError: 'NoneType' object has no attribute 'lower'
2022-05-12T20:31:47.451100+00:00 heroku[web.1]: Process exited with status 1
2022-05-12T20:31:47.494216+00:00 heroku[web.1]: State changed from starting to crashed
Horhik commented 2 years ago

Are you using it with docker-compose? You're missing several environment variables

condr-at commented 2 years ago

Yes. And with variables in env.sh It worked for local docker

image
Horhik commented 2 years ago

Hmmm.... Try to remove build: context .It is preferring local docker to fetching container from dockerhub. And... now hide your token :) I think now u should recreate it for your own security

condr-at commented 2 years ago

The token is totally safe, it's not even a half of it. :) Tried without build: context .I

In local docker everything runs like a charm and every variable is in the right place. As for Heroku – same result. Variables lost somewhere. I already deleted the entire app on Heroku and re-deployed it, and nothing changed.

Horhik commented 2 years ago

Hmm... strange.. You can try to run it without docker :) https://github.com/Horhik/Instagram2Fedi/blob/main/Docs.md

Maybe you should try to specify an .env file in compose file env_file: .env

condr-at commented 2 years ago

Maybe it's because Heroku uses only src/main.py file. All errors come from it. And there are no arguments by default.

image
condr-at commented 2 years ago

I was right. Somehow, Heroku uses variables only from main.py, and it works like this.

I used Heroku git to deploy the app.

image

The question is how to fix this and change the settings in the env file. Or the docker compose file. For example for two bots, like you've mentioned in other issue.

services:
  bot-1: # FIRST BOT
    build:
      context: .
    image: "horhik/instagram2fedi:latest"
    environment:
      - YOUR_CONTAINER_NAME=<whatever>
      - I2M_INSTAGRAM_USER=<instagram username> # FIRST INSTAGRAM ACCOUNT
      - I2M_INSTANCE=<mastodon or pixelfed instance>
      - I2M_TOKEN=<token> # SAME TOKEN
     # other variables ....

  bot-2: # SECOND BOT
    build:
      context: .
    image: "horhik/instagram2fedi:latest"
    environment:
      - YOUR_CONTAINER_NAME=<whatever>
      - I2M_INSTAGRAM_USER=<instagram username> # SECOND INSTAGRAM ACCOUNT
      - I2M_INSTANCE=<mastodon or pixelfed instance>
      - I2M_TOKEN=<token> # SAME TOKEN
     # other variables ....
condr-at commented 2 years ago

Maybe it's all about python version, idk.

Horhik commented 2 years ago

I think there's a problem in how do you set up docker with heroku. https://devcenter.heroku.com/articles/build-docker-images-heroku-yml

condr-at commented 2 years ago

Yeah. Since i'm no programmer at all, any help with heroku.yml?

I used this default one (not working, all the same with variables):

build:
  docker:
    web: Dockerfile

logs.TXT

condr-at commented 2 years ago

UPD It seems Heroku uses only its own configured variables, not env.sh. But still, after I define them arguments.py doesn't work and returns ❗ -> Wrong Argument Name!...

Vars from docker-compose are ignored as well.

Horhik commented 2 years ago

@alex-ash Wrong argument Name means what you made a typo or incorrect input.

You can pass your arguments not only with docker but with command line flags. Then you don't even need docker :)

Screenshot from 2022-05-14 10-14-59

try to:

python -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
./insta2fedi --use-docker false --instagram-user dalsfkjsdl --instance sdfkljhsdlfkjsdf --token asfsfasdfssdfsadfsdfs --check-interval 10 --post-interval 10 --use-mastodon 4
condr-at commented 2 years ago

There are no errors in arguments on local docker. I will try though. Thank you so much.

Btw is there any way to run several bots through command line? With docker, you advise composing them one by one.

condr-at commented 2 years ago

Okay, I've made huge progress!

Here's news. Heroku needs a Procfile where run.sh is specified. In run.sh it found a syntax error:

image

So I deleted / and env was successfully imported. After that, I encountered new syntax errors in other commands in run.sh.

image

And so on. After we finish this, I promise, you'll be able to add complete heroku instructions into your docs. Any suggestions about syntax in run.sh?

Horhik commented 2 years ago

Damn.... you're running bash file via python interpreter... obviously it will completely consist of syntax errors

Horhik commented 2 years ago

Anyway, this problem is not specific about my project. It's better to ask about running docker apps inside Heroku and about problems with environment variables on Reddit or Stack Overflow. Due to that, I'm closing this issue