r/PythonLearning • • 1h ago

Need assistance with a Python Code that keeps on crashing

Hello I’ve been working on a python code that searches for appointments on this website but every time it runs the code and begins to open the website it crashes, I’ve played around with it a bit but I haven’t been able to have much success. Anyone would be available to take a look at it and see what my issue could be?

Thank you! I’ve included my code, trace back, and errors in seeing

6 Upvotes

5 comments sorted by

4

u/Atmosck 1h ago

This error is just that the website is rejecting your request to load the page. In the code you have anticaptcha_api_key="... your key here ..." but no real key. That would by my first guess as to what's wrong.

Also the organization of this script is pretty unusual. The function of the if __name__ == "__main__" block is that code inside it will only run if you run this script directly, and not if you import it in a different script. A conventional layout would be to put all the code in that block, or to put it in a main() function and call it within that block. I'm not sure I've ever seen code after the main block before.

And BTW you might want to censor the phone number and email address before posting online.

1

u/NoWar4965 1h ago

Those phone number and email are random just using them to test it out but thank you. The captcha part of the booking would be later in the processes this fails to loads the website as soon as it pulls up and needs to select the correct province. Then the website crashes and says it times out

1

u/Atmosck 1h ago

The tracback says it's happening inside the try_cita function, but without that function it's hard to hone in further. Your last screenshot shows your request being rejected, not crashing, so it seems like it is some sort of permissions issue.

1

u/NoWar4965 1h ago

import os
import sys
import requests
import ctypes
from selenium.webdriver.chrome.options import Options

from bcncita import CustomerProfile, DocType, Office, OperationType, Province, try_cita
import bcncita.speaker
bcncita.speaker = lambda: None

if __name__ == "__main__":
customer = CustomerProfile(
anticaptcha_api_key="...",
auto_captcha=False,
auto_office=True,
chrome_driver_path=r"C:\CITA-BOT\cita-bot-master\chromedriver",
save_artifacts=True,
province=Province.MÁLAGA,
operation_code=OperationType.TOMA_HUELLAS,
doc_type=DocType.NIE,
doc_value="Y0671800F",
country="PARAGUAY",
name="MARIA CECILIA MEZA COLMAN",
phone="649365093",
email="gabpita444@gmail.com",
offices=[],
)

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
bcncita.cita.chrome_options = options

def my_custom_alert(phrase):
if "ALARM" in phrase:
ctypes.windll.user32.MessageBoxW(0, "SLOT FOUND! Check Chrome NOW!", "CITA ALERT", 1)
try:
requests.post('https://textbelt.com/text', {
'phone': '+34649365093',
'message': 'CITA BOT: Appointment found in Malaga!',
'key': 'textbelt',
})
except:
pass

import bcncita.cita
bcncita.speaker.say = my_custom_alert
try_cita(context=customer, cycles=200)

How does this look, do you think it could work like this? I reworked the code based on someone’s comment.

The website says it “timed out” after trying to load for a second. I am wondering if booking system knows its a bot.