Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.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
行动没有';t在python文件中生成有效的JSON对象_Python_Json_Ibm Cloud - Fatal编程技术网

行动没有';t在python文件中生成有效的JSON对象

行动没有';t在python文件中生成有效的JSON对象,python,json,ibm-cloud,Python,Json,Ibm Cloud,我正在使用IBM cloud函数的两个操作—write1和write2(都使用PYTHON) 我创建了一个序列,该序列应该将值从write1传递到write2 我在write1action中编写了一个PYTHON代码,但它抛出了一些JSON错误 编写1个Python文件: 导入操作系统 导入系统 导入json 导入请求 导入ibm_boto3 从ibm_botocore.client导入配置,ClientError cos=ibm_boto3.resource(“s3”, ibm_api_key

我正在使用IBM cloud函数的两个操作—
write1
write2
(都使用PYTHON)

我创建了一个序列,该序列应该将值从
write1
传递到
write2

我在
write1
action中编写了一个PYTHON代码,但它抛出了一些JSON错误

编写1个Python文件:

导入操作系统
导入系统
导入json
导入请求
导入ibm_boto3
从ibm_botocore.client导入配置,ClientError
cos=ibm_boto3.resource(“s3”,
ibm_api_key_id='my-api-key',
ibm_服务_实例_id='my-instance-id',
config=config(signature\u version=“oauth”),
端点https://s3.eu-gb.cloud-object-storage.appdomain.cloud'
)
def get_项目(存储桶名称、项目名称):
a={“从bucket中检索项”:bucket_name,“key”:item_name}
打印(json.dumps(a))
尝试:
file=cos.Object(bucket\u name,item\u name).get()
返回文件[“Body”].read()
除以下情况外:
w={“客户端错误”:be}
打印(json.dumps(w))
例外情况除外,如e:
y={“无法检索文件内容”:e}
打印(json.dumps(y))
def test():
x=获取_项('cloud-college-bucket0','abc.txt')
打印(x.decode('utf-8'))
如果x不是无:
字符串_大写=x.upper();
n={“String in Uppercase=“:String_in_Uppercase.decode('utf-8')}
b=json.dumps(n)
印刷品(b)
def主(dict):
返回测试()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
main()
它抛出的错误:

结果:

{
  "error": "**The action did not produce a valid JSON response**: null\n"
}

Logs:

[
  "2019-10-08T13:01:56.339677Z    stderr: /usr/local/lib/python3.7/site-packages/ibm_botocore/vendored/requests/api.py:67: DeprecationWarning: You are using the post() function from 'ibm_botocore.vendored.requests'.  This is not a public API in ibm_botocore and will be removed in the future. Additionally, this version of requests is out of date.  We recommend you install the requests package, 'import requests' directly, and use the requests.post() function instead.",

  "2019-10-08T13:01:56.339748Z    stderr: DeprecationWarning",

  "2019-10-08T13:01:56.339755Z    stderr: /usr/local/lib/python3.7/site-packages/ibm_botocore/vendored/requests/models.py:169: DeprecationWarning: 

Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working",

  "2019-10-08T13:01:56.339759Z    stderr: if isinstance(hook, collections.Callable):",

  "2019-10-08T13:01:56.339678Z    stdout: {\"Retrieving item from bucket\": \"cloud-college-bucket0\", \"key\": \"abc.txt\"}",

  "2019-10-08T13:01:56.339772Z    stdout: hello friends",

  "2019-10-08T13:01:56.339776Z    stdout: {\"String in Uppercase =\": \"HELLO FRIENDS\"}",

  "2019-10-08T13:01:56.340Z       stderr: The action did not initialize or run as expected. Log data might be missing."

]

它说的是
导入请求
,我做了,但问题仍然存在

我也会说使用
request.post
函数,但如何使用以及在何处使用是我无法理解的如何解决这个JSON问题?


所需的输出显示在日志中。

从一开始,我就可以看到
test
函数只打印JSON,但从不返回它。但是,如果您看到示例Python操作,它应该总是返回JSON

import sys

def main(dict):
    return { 'message': 'Hello world' }
此外,您还可以在操作中使用Python运行时之前检查受支持的包列表


如果您有一个不在列表中的包,您可以始终或

您的意思是
请求
包?