相关疑难解决方法(0)

python - 防止IOError:[Errno 5]在没有stdout的情况下运行时输入/输出错误

我有一个脚本通过cronjob在服务器上自动运行,它导入并运行其他几个脚本.

其中一些使用打印,这自然会创建,IOError: [Errno 5] Input/output error因为脚本运行时没有连接任何SSH /终端,因此没有正确的标准设置.

关于这个主题有很多问题,但我找不到任何实际解决它的人,假设我无法删除打印或更改执行的脚本.

我尝试了几件事,包括:

class StdOut(object):
    def __init__(self):
        pass
    def write(self, string):
        pass
sys.stdout = StdOut()
sys.stderr = StdOut()
Run Code Online (Sandbox Code Playgroud)

from __future__ import print_function
import __builtin__

def print(*args, **kwargs):
        pass
    __builtin__.print = print
Run Code Online (Sandbox Code Playgroud)

但它都不起作用.我认为它只会影响模块本身,而不会影响我以后导入/运行的模块.

那么如何创建一个会影响流程中所有模块的存根标准输出?就像我说的,我不想更改从主模块执行的脚本,但我可以更改导入模块中的所有内容.只是为了清除 - 一切都是进口的,没有新的流程产生等.

谢谢,

python stdout python-2.7

7
推荐指数
1
解决办法
7280
查看次数

我在 django 上运行 api 时遇到错误“[Errno 5] 输入/输出错误”

Django API 代码:

def post(self,request)-> JsonResponse:
        try:
            self.email = request.data['email']
            self.mobile = request.data['mobile']
            self.password = request.data['password']
        except Exception as e:
            return JsonResponse(create_failure('400',f"invalid payload {e}","fail"))
        try:
            res = {}
            jwt_token = ''
            if self.email:
                password = Customer.objects.get(email=self.email).password
                username  = Customer.objects.get(email=self.email).username
                print(password)
                if check_password(self.password,password) :
                    jwt_token = make_jwt_token({'username':username})
                else:
                    return JsonResponse(create_failure('500',f"Invalid password","fail"))
            elif self.mobile:
                password = Customer.objects.get(mobile=self.mobile).password
                username  = Customer.objects.get(mobile=self.mobile).username
                if check_password( password,self.password) :
                    jwt_token = make_jwt_token({'username':username})
                else:
                    return JsonResponse(create_failure('500',f"Invalid password","fail"))
            res['token'] = jwt_token
        except Exception as e:
            return JsonResponse(create_failure('400',f"error in verifying …
Run Code Online (Sandbox Code Playgroud)

python linux django cpanel

5
推荐指数
2
解决办法
7162
查看次数

标签 统计

python ×2

cpanel ×1

django ×1

linux ×1

python-2.7 ×1

stdout ×1