InvalidSchema (“Для ‘%s’” % url не найдено адаптеров подключения)

#python #django #http #error-handling

#python #django #http #обработка ошибок

Вопрос:

Я пытаюсь запустить свой скребок, но есть проблема с URL-адресами. Они выглядят так: //ocdn.eu/pul …

Сообщение об ошибке: поднять InvalidSchema («Не найдено адаптеров подключения для %s'» % url) запросы.исключения.InvalidSchema: не найдено адаптеров подключения для ‘/http:///http ://

Ошибка возникает в строке r = session.get. Спасибо за помощь!

 for post in posts:
    title = post.find('span', {'class': 'title'}).get_text()
    link = post.find("a")['href']
    image_source = post.find('img')['src']
    image_source_solved = "http://".join(image_source)

    # stackoverflow solution

    media_root = '/Users/mat/Desktop/jspython/just django/dashboard/media_root'
    if not image_source.startswith(("data:image", "javascript")):
        local_filename = image_source.split('/')[-1].split("?")[0]
        r = session.get(image_source_solved, stream=True, verify=False)
        with open(local_filename, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                f.write(chunk)

        current_image_absolute_path = os.path.abspath(local_filename)
        shutil.move(current_image_absolute_path, media_root)
  

Ответ №1:

Я изменил эту строку:

 image_source_solved = "http://".join(image_source)
  

для этой строки:

 image_source_solved = "http:{}".format(image_source)