r/PythonLearning • • 11d 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

23 Upvotes

8 comments sorted by

6

u/Atmosck 11d 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.

2

u/NoWar4965 11d 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 11d 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 11d 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="[email protected]",
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.

1

u/Chemical_Award_5184 11d ago

Here's your timeout exception error: "def initial_page(driver: webdriver, context: CustomerProfile, fast_forward_url, fast_forward_url2):

if context.first_load:

driver.delete_all_cookies()

driver.set_page_load_timeout(300 if context.first_load else 50)

# Fix chromedriver 103 bug

time.sleep(1)

driver.get(fast_forward_url)

time.sleep(5)

if context.first_load:

try:

driver.execute_script("window.localStorage.clear();")

driver.execute_script("window.sessionStorage.clear();")

except Exception as e:

logging.error(e)

pass

driver.get(fast_forward_url2)

time.sleep(5)

resp_text = body_text(driver)

if "INTERNET CITA PREVIA" not in resp_text:

context.first_load = True

raise TimeoutException

context.first_load = False"

1

u/Extension_Fig_2168 10d ago

Where should I add this line of code?

1

u/Chemical_Award_5184 10d ago

No, that's the error. The conditional for "INTERNET CITA PREVIA", that's where your error came from. Your connection didn't go through for some reason, maybe missing certs or http header or field or something, could be that anticaptcha-api-key, know what I mean?