0

我是 Python 的新手。我试图到处寻找解决方案,但无法通过。

我做了一个 Scrapy 项目,由于项目结构,蜘蛛默认存储在/spiders目录中。

/project问题:我们通常从其中包含的目录运行爬虫/spiders。包含这段代码后问题开始了:

def implicit():
    from google.cloud import storage

    # If you don't specify credentials when constructing theclient,the
    # client library will look for credentials in the environment.
    storage_client = storage.Client()

# Make an authenticated API request
    buckets = list(storage_client.list_buckets())

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "remote url of the json file"

/project如果我从目录中抓取蜘蛛并抛出错误,上面的代码不会捕获远程文件

“找不到文件 json_filename.json。”

但是当我从目录中抓取蜘蛛时,/project/spider它运行顺利,没有任何错误。

我想我在这里遗漏了一些基础知识,与爬行位置或环境变量有关。谢谢人们。

4

0 回答 0