Скрипт не работает на хостинге
Вообщем написал скрипт для беседы ВК, который присылает расписание по команде. Если запускать скрипт на компе, то всё отлично работает, на хостинге же ошибка, показанная на фото
def send_schedule(req_date):
url = 'http://oreluniver.ru/schedule//7980///1630281600367/printschedule'
bardak = requests.get(url)
timetable = json.loads(bardak.text)
print(bardak.text)
title_subject = []
type_lesson = []
global number_lesson
number_lesson = []
date_lesson = []
korpus = []
number_room = []
surname = []
name = []
global second_name
second_name = []
global time_lesson
time_lesson = ['','8:30 - 10:00','10:10 - 11:40','12:00 - 13:30','13:40 - 15:10','15:20 - 16:50','17:00 - 18:30','18:40 - 20:10','20:15 - 21:45']
send_msg = ''
for i in timetable:
if i == 'Authorization':
break
title_subject.append(timetable[i]['TitleSubject'])
type_lesson.append(timetable[i]['TypeLesson'])
number_lesson.append(timetable[i]['NumberLesson'])
date_lesson.append(timetable[i]['DateLesson'])
korpus.append(timetable[i]['Korpus'])
number_room.append(timetable[i]['NumberRoom'])
surname.append(timetable[i]['Family'])
name.append(timetable[i]['Name'])
second_name.append(timetable[i]['SecondName'])
for i in range(len(date_lesson)):
if date_lesson[i][-5:] == req_date:
gender = second_name[i][-1]
send_msg += '\n📖'+title_subject[i]+', '+type_lesson[i]+'.\n'+'⏰'+time_lesson[number_lesson[i]]+'\n'+gender_detector(gender)+surname[i]+' '+name[i]+' '+second_name[i]+'\n'+'🚪'+korpus[i]+'-'+number_room[i]+'\n_____________________\n'
return send_msg+'вот бы мне милого мальчика который напишет ночью: слышь, я те хостинг нашёл💝'
Ответы (1 шт):
При отправке запроса на указанный в вопросе адрес с бесплатного аккаунта pythonanywhere в ответе приходит такой результат:
>>> import requests
>>> result = requests.get('http://oreluniver.ru/schedule//7980///1630281600367/printschedule')
>>> print(result.text)
<HTML>
<HEAD>
Access Denied
</HEAD>
<BODY>
<h1>Access Denied</h1>
<p>
Access to arbitrary websites is not available from free accounts;
you can only access sites that are on our
<a href="http://www.pythonanywhere.com/whitelist">whitelist</a>.
If you want to suggest something to add to our whitelist
drop us a line at [email protected]. It will have
to have an official public API.
</p>
<p>
Alternatively, you can sign up for a paid account at
<a href="http://www.pythonanywhere.com/account/">http://www.pythonanywhere.com/account/</a>
</p>
<p>
If you have already got a paid account and you're still getting this messge,
you may need to reload your web app (from the "Web" tab) or restart
your consoles. If that doesn't help, drop us a line at [email protected].
</p>
</BODY>
Общий смысл этого текста в том, что с бесплатного аккаунта pythonanywhere нельзя получить доступ к произвольному сайту, а только к сайтам из "белого" списка.
Решение — оплатить минимальную платную подписку pythonanywhere (5$ за месяц, см. https://www.pythonanywhere.com/pricing/), либо искать другой бесплатный хостинг без подобных ограничений. Либо найти где-то одноплатный компьютер типа raspberry pi, хоститься на нем.
