Deployment doesn't work while testing is okay

Hi, I have a Repl with a telegram bot which is working properly when I run it for test, but then when I deploy it with Reserved VM using Background Worker, the bot doesn’t work. In previous version of this bot, the code was working properly with Background Worker, so it could be something after my last modification

this is the logs of the deployment:

2024-02-17T20:39:02Z info: Deployment: 28a15ed2-547b-44c2-be19-d98fd87ba7da
2024-02-17T20:39:02Z info: Build: bd365b01-fc77-4b05-9a72-da09dd88bcf6
2024-02-17T20:39:02Z info: Connecting to builder
2024-02-17T20:39:02Z info: Deployment: 28a15ed2-547b-44c2-be19-d98fd87ba7da
2024-02-17T20:39:02Z info: Build: bd365b01-fc77-4b05-9a72-da09dd88bcf6
2024-02-17T20:39:02Z info: Connecting to builder
2024-02-17T20:39:04Z info: Builder connected
2024-02-17T20:39:04Z info: Installing packages
--> poetry lock --no-update

Resolving dependencies...


Writing lock file

--> poetry install

Installing dependencies from lock file


Package operations: 0 installs, 1 update, 
0 removals


  • Updating httpx (0.26.0 -> 0.25.2)

2024-02-17T20:39:15Z info: Skipping Build as no Build command set
2024-02-17T20:39:15Z info: Pushing pid1 binary layer...
2024-02-17T20:39:17Z info: Created pid1 binary layer
2024-02-17T20:39:18Z info: Skipping Python layer creation
2024-02-17T20:39:18Z info: Skipping Node layer creation
2024-02-17T20:39:18Z info: Pushing hosting layer...
2024-02-17T20:39:18Z info: Pushing Repl layer...
2024-02-17T20:39:18Z info: Retrieved cached nix layer
2024-02-17T20:39:19Z info: Created hosting layer
2024-02-17T20:39:46Z info: Created Repl layer
2024-02-17T20:39:47Z info: Pushed image manifest
2024-02-17T20:39:47Z info: Pushed soci index manifest
2024-02-17T20:39:57Z info: Creating virtual machine
2024-02-17T20:40:32Z info: Virtual machine created
2024-02-17T20:40:32Z info: Waiting for deployment to be ready
starting up user application
initializing deployment without listening for application ports
2024-02-17T20:41:09Z info: Deployment successful

So basically the problem could be that the code doesn’t listen for application ports

How can I solve the issue and make the bot working properly with deployments?

thank you in advance

1 Like

Well, a repl link would be appreciated, but you can define external port to internal port connection in your .replit file, and deployment settings as well, so check what port your app starts on (I think it has to be 3000+) and set that as local port in deployment settings.

6 Likes

Hey, @RicascoLTD!
Reserved VM Background Workers are only for program without a direct web server. If your Telegram bot requires this, try deploying it as a Reserved VM Web Server.

4 Likes

@7heMech @RedCoder thank you for the help. The code is linked to OpenAI API and Coingecko API, until I was using just OpenAI API in the code, “Background workers” was the right one, since I added Coingecko probably it stopped to work. I say “probably” because I didn’t deploy for every update of the code.
EDIT: I just checked the previous version that works properly with “Background workers” and the new one that doesn’t work with “Background workers”, and the .replit file and pyproject.toml are the same. In the new version I just added functions with Coingecko API, function to ban user and a function to delete the fixed message when a user leaves a group (in this last function I had to add this line of code application.add_handler(MessageHandler(filters.StatusUpdate.LEFT_CHAT_MEMBER, handle_leaving_user)) in the main function to run the bot)

I tried “Web Server” as well, but in that case the deployment fails and this is part of the log, so I think I have to use Background workers:

02/18/24 12:38:13 AM
starting up user application
02/18/24 12:38:05 AM
exec [python3 main.py] error=exec: already started
02/18/24 12:38:05 AM
exec [python3 main.py] error=exit status 1
02/18/24 12:38:04 AM
TypeError: AsyncClient.__init__() got an unexpected keyword argument 'proxy'

then I tried with “Background workers” again, the deploy was completed as usual and the bot didn’t respond to any user’s input, this was the logs:

02/18/24 01:00:27 AM

starting up user application

02/18/24 01:00:21 AM

exec [python3 main.py] error=exec: already started

02/18/24 01:00:21 AM

exec [python3 main.py] error=exit status 1

02/18/24 01:00:18 AM

TypeError: AsyncClient.__init__() got an unexpected keyword argument 'proxy'

02/18/24 01:00:18 AM

return httpx.AsyncClient(**self._client_kwargs) # type: ignore[arg-type]

02/18/24 01:00:18 AM

self._client = self._build_client()

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/.pythonlibs/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 212, in _build_client

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/.pythonlibs/lib/python3.10/site-packages/telegram/ext/_applicationbuilder.py", line 253, in _build_request

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/.pythonlibs/lib/python3.10/site-packages/telegram/ext/_applicationbuilder.py", line 273, in _build_ext_bot

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/.pythonlibs/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 177, in __init__

02/18/24 01:00:18 AM

return HTTPXRequest(

02/18/24 01:00:18 AM

bot: Bot = self._build_ext_bot() # build a bot

02/18/24 01:00:18 AM

request=self._build_request(get_updates=False),

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/.pythonlibs/lib/python3.10/site-packages/telegram/ext/_applicationbuilder.py", line 303, in build

02/18/24 01:00:18 AM

application = ApplicationBuilder().token(TOKEN).build()

02/18/24 01:00:18 AM

File "/home/runner/31bca238-cf82-4f26-bb3d-93bb4341076d/main.py", line 270, in <module>

02/18/24 01:00:18 AM

Traceback (most recent call last):

02/18/24 01:00:18 AM

2024-02-18 01:00:18,568 - httpx - INFO - HTTP Request: PUT https://bf621970-e898-4548-abdf-7ee4aa572f32.us-east4-0.gcp.cloud.qdrant.io:6333/collections/decrypted_collection/points?wait=true "HTTP/1.1 200 OK"

02/18/24 01:00:18 AM

2024-02-18 01:00:18,101 - httpx - INFO - HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"

02/18/24 01:00:13 AM

2024-02-18 01:00:13,503 - httpx - INFO - HTTP Request: PUT https://bf621970-e898-4548-abdf-7ee4aa572f32.us-east4-0.gcp.cloud.qdrant.io:6333/collections/decrypted_collection "HTTP/1.1 200 OK"

02/18/24 01:00:13 AM

2024-02-18 01:00:13,230 - httpx - INFO - HTTP Request: DELETE https://bf621970-e898-4548-abdf-7ee4aa572f32.us-east4-0.gcp.cloud.qdrant.io:6333/collections/decrypted_collection "HTTP/1.1 200 OK"

02/18/24 12:59:39 AM

initializing deployment without listening for application ports

02/18/24 12:59:28 AM

starting up user application

this is my .replit file:

entrypoint = "main.py"
disableGuessImports = true
disableInstallBeforeRun = true
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[unitTest]
language = "python3"

[deployment]
run = ["python3", "main.py"]
deploymentTarget = "gce"

The code is long and I wouldn’t share the repl to be honest, but I can share the part of the code where the issue could be find if you have an idea
Really hope you can help me

Thank you in advance

I’m afraid without the code I can’t help you, but if you don’t want to share it, try making a minimal reproducible example of the problem.

2 Likes

I solved! I just installed the previous versions of the dependencies “httpx” and “python-telegram-bot”, the same versions of the ones in the bot that was working properly, and then add them in “pyproject.toml”.

Now the “Background Workers” of deployment is perfect, I’m happy!

Thank for you for the help!

Just a question: I feel like an elephant surrounded by crystals ahahah just a simple update of a dependency can cause important errors in the code that make the bot doesn’t work, and it’s the second time I install previous versions of dependencies to not destroy the code I built :smiley:

How can I become “good at this”? so how can I understand what I have to modify in the code if I update a dependency?

Sorry for my basic language, but I’m just a no coder who, thanks to ChatGPT and an amazing platform like Replit, was able to build a pretty good custom RAG solution on Telegram :slight_smile:

2 Likes

I’d recommend searching for the package in question, and trying to find a changelog like this here:

Breaking changes are usually documented there.

1 Like

Please mark your own reply as the solution.

1 Like

This is gonna sound lame lol, but practice. Practice, practice, practice. The more I practiced just playing around with different types of proggraming, and made new things that were more complex, I started to understand those laungagues much, much deeper. Think about it like you are learning a new natural laungage

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.