Issue with Python Code

Status: Closed · Asked by inochi on · 0 views

inochi — Question ·
Task History ID: IjU3NmQwNTZlMDYzNzA0MzQ1MjZiNTUzNCI_3D_pc

Hello,

after updating Python & Javascript Code, I can no longer get the codes I had before to work.

I give an example just to understand:

import datetime
import random
now = datetime.datetime.now() # ottieni l'orario corrente in Italia
delta = datetime.timedelta(minutes=random.randint(10, 60)) # genera un intervallo casuale tra 10 e 60 minuti
random_time = now - delta # sottrai l'intervallo casuale all'orario corrente per ottenere un orario casuale precedente
time_diff = now - random_time
hours_diff = time_diff.seconds // 3600
minutes_diff = (time_diff.seconds // 60) % 60
if hours_diff == 0:
time_ago = f"{minutes_diff} minuti fa"
elif hours_diff == 1:
time_ago = f"1 ora e {minutes_diff} minuti fa"
else:
time_ago = f"{hours_diff} ore e {minutes_diff} minuti fa"
output = [{"random_time": time_ago}]
print(output)

I would use this code to randomly generate the hours and minutes and then the output would return with the random numbers. Example: 1 hour and 30 minutes ago.

After updating, most of the code gives me an error.
In this particular case, with this code I posted, I get the error:

"name 'random_time' is not defined"

How can I solve it?

Thank you

Attachments

Screenshot del 03-01-2024 alle 17.16@2x.png
Arshil Ahmad — Reply ·

Hi @inochi,

Please record a short screen recording running this code in an online compiler. Additionally, run the same code in Code by Pabbly and show the responses you get in both scenarios.

inochi — Reply ·

Of course.
The problem is only on Pabbly Connect.

Here's the result on an online compiler:
[{'random_time': '42 minuti fa'}]

It's working perfectly.

Here's the result on Pabbly Connect for the same code:
Error: name 'random_time' is not defined

Before the Pabbly Code update everything was working fine. In fact, I noticed that the Code I was using had "deprecated" in it so I updated Code and put the latest version in but it still doesn't work.

How can I solve it?

Thanks

Attachments

Screenshot del 04-01-2024 alle 09.51@2x.png
Screenshot del 04-01-2024 alle 09.48@2x.png
Arshil Ahmad — Reply ·

I tried to run this code in an online compiler and got an error. I request you to please record a short video running the exact same code on Code by Pabbly and an online compiler.

Arshil Ahmad — Reply ·

Thank you for sharing the video. Please allow us some time to look into this concern. We will get back to you with an update soon.

inochi — Reply ·

Okay, now it's working. What has changed? Can you give me specific directions so that all the codes work?

inochi — Reply ·

Same issue with this code:
https://pastebin.com/C49NsMqc

It's working well on Python compiler (see the screenshot) but it's giving me an error on Pabbly Connect...

Could you please help me?

Thanks

Attachments

Screenshot del 07-01-2024 alle 17.09@2x.png
Screenshot del 07-01-2024 alle 17.08@2x.png
Arshil Ahmad — Reply ·

Please allow us some time to look into this issue. We will get back to you shortly.

Arshil Ahmad — Reply ·

We have made some changes at the backend. The code should work now.

inochi — Reply ·

It's working!
Thanks

Back to all forum threads · Log in to reply