Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
允许Python模块在AWS Lambda上写入磁盘_Python_Python 3.x_Amazon Web Services_Aws Lambda_Google Search - Fatal编程技术网

允许Python模块在AWS Lambda上写入磁盘

允许Python模块在AWS Lambda上写入磁盘,python,python-3.x,amazon-web-services,aws-lambda,google-search,Python,Python 3.x,Amazon Web Services,Aws Lambda,Google Search,我在AWS Lambda上使用Python模块googlesearch,但它抛出了一个错误——我怀疑是因为它想根据AWS Lambda上没有的文件夹结构将cookie写入磁盘 此外,AWS Lambda仅允许写入/tmp/ 怎么办?我唯一能想到的就是从github下载模块代码并集成到我的Python脚本中——我真的不想走这条路 谢谢你的建议 以下是AWS Lambda错误报告: Errno 30] Read-only file system: './.google-cookie': OSErro

我在AWS Lambda上使用Python模块googlesearch,但它抛出了一个错误——我怀疑是因为它想根据AWS Lambda上没有的文件夹结构将cookie写入磁盘

此外,AWS Lambda仅允许写入/tmp/

怎么办?我唯一能想到的就是从github下载模块代码并集成到我的Python脚本中——我真的不想走这条路

谢谢你的建议

以下是AWS Lambda错误报告:

Errno 30] Read-only file system: './.google-cookie': OSError
Traceback (most recent call last):
File "/var/task/scriverto.py", line 176, in lambda_handler
url_list = generate_URL_list(query,n) #call URL generator routine in gsearch
File "/var/task/scriverto.py", line 58, in generate_URL_list
for url in search(query, tld = "co.uk", lang='en', pause = 2, stop=n): 
#can also add tld to limit to country e.g. tld='uk
File "/var/task/googlesearch/__init__.py", line 330, in search
get_page(url_home % vars())
File "/var/task/googlesearch/__init__.py", line 151, in get_page
cookie_jar.save()
File "/var/lang/lib/python3.6/http/cookiejar.py", line 1875, in save
with open(filename, "w") as f:
OSError: [Errno 30] Read-only file system: './.google-cookie'
阅读
googlesearch
模块的:

# Cookie jar. Stored at the user's home folder.
home_folder = os.getenv('HOME')
if not home_folder:
    home_folder = os.getenv('USERHOME')
    if not home_folder:
        home_folder = '.'   # Use the current folder on error.
cookie_jar = LWPCookieJar(os.path.join(home_folder, '.google-cookie'))
try:
    cookie_jar.load()
except Exception:
    pass

您似乎可以将环境变量
HOME
USERHOME
设置为
/tmp
,这将导致
googlesearch
使用这些位置将cookiejar写入磁盘。

。谢谢Matt。如何设置环境变量?从主脚本调用模块时,我尝试将home='/tmp'与其他参数(如查询、语言、TLD等)一起包括在内,但它抛出了一个错误。我在github页面的任何地方都找不到可选参数列表。有在AWS LambdaGreat中设置环境变量的说明-谢谢Matt。我将/tmp作为函数页面上的一个环境变量设置为HOME,看起来它起作用了。