python - InvalidSchema (“No connection adapters were found for '%s'”%url)

标签 python django http error-handling

我正在尝试运行我的刮板,但是网址有问题。他们看起来像这样://ocdn.eu/pul ...

错误信息:
引发InvalidSchema(“未找到'%s'的连接适配器”“%url)
request.exceptions.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)

最佳答案

我更改了这一行:

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

对于这一行:
image_source_solved = "http:{}".format(image_source)

关于python - InvalidSchema (“No connection adapters were found for '%s'”%url),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55579974/

相关文章:

django - 我对 app.py 中使用的就绪函数感到困惑

ASP.NET - 将所有 https 请求重写为 http

php - 从 bitbucket 获取电子邮件

python - 编译 Python 3.4 不是复制 pip

python - 如何根据其他列 'Applicant_Income' 的条件绘制列 'Education"的直方图?

python - 如何获取使用 JavaScript 构建的 anchor 标记的重定向链接?

node.js - 来自多个调用的流式 http 响应

Python vs Groovy vs Ruby? (基于相关标准)

django - 在 Django 中找不到静态文件

python - Django 中不寻常的 setdefault