Я получаю эту ошибку. Исключение игнорируется в: <_io.TextIOWrapper name='<stdout>' mode='w'coding='cp1252'> OSError: [EPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Я получаю эту ошибку. Исключение игнорируется в: <_io.TextIOWrapper name='<stdout>' mode='w'coding='cp1252'> OSError: [E

Сообщение Anonymous »

Я помещаю несколько файлов журналов в скрипт Python, который затем передаю в голову следующим образом:

Код: Выделить всё

cat *mongodb.log.* | python jsonFetcher.py -b 20240101000000 -e 20250101000000 | head
вывод следующий: в конце я получаю ошибку. Я не получаю сообщение об ошибке при подключении к другому скрипту Python:

Код: Выделить всё

{"t":{"$date":"2024-06-09T02:47:32.053+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"192.168.240.198:57790","uuid":"8e485191-5c63-457e-b341-14515b593ef1","connectionId":207933,"connectionCount":773}}
{"t":{"$date":"2024-06-09T02:47:32.084+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn207932","msg":"client metadata","attr":{"remote":"192.168.240.198:57776","client":"conn207932","negotiatedCompressors":[],"doc":{"application":{"name":"MongoDB Automation Agent v13.16.2.8826 (git: 36d72fa13b663f402e1285ab8458536766897530)"},"driver":{"name":"mongo-go-driver","version":"v1.12.0-cloud"},"os":{"type":"linux","architecture":"arm64"},"platform":"go1.21.10"}}}
{"t":{"$date":"2024-06-09T02:47:32.085+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"192.168.240.198:57794","uuid":"3d76d2c2-2298-4fc8-80b6-e029d0d1f933","connectionId":207934,"connectionCount":774}}
Exception ignored in: 
OSError: [Errno 22] Invalid argument
Вот скрипт, отправляющий в голову свои входные данные:

Код: Выделить всё

#!/usr/bin/env python3

"""

File: jsonFetcher.py
Author: Dennis Spera
Date: 2024-06-24
Description: Extract json from mongod.log on stdin based on date ranges.

"""

import sys
import json as j
from datetime import datetime
import re as regex
from commandlines import Command as cmd

b = str()
e = str()
start_d_t_fmt = None
end_d_t_fmt = None
max_input_length = 14
min_input_length = 8

def is_json(json):
try:
j.loads(json)
except ValueError:
return False
return True

try:
c = cmd()

try:
b = c.get_definition('b')
if len(b) > max_input_length:
sys.stderr.write('beginning timestamp exceeds beginning timesamp length of ' + str(max_input_length))
sys.exit(0)
if len(b) < min_input_length:
sys.stderr.write('beginning timestamp less than beginning timesamp length of ' + str(min_input_length))
sys.exit(0)

try:
test = int(b)
except:
sys.stderr.write('beginning timestamp is an invalid data format')
sys.exit(0)

padding = max_input_length - len(b)

if padding > 0:
for i in range(1, padding+1, 1):
b=b+'0'

e = c.get_definition('e')
if len(e) > max_input_length:
sys.stderr.write('ending timestamp exceeds ending timesamp length of ' + str(max_input_length))
sys.exit(0)
if len(b) < min_input_length:
sys.stderr.write('ending timestamp less than ending timesamp length of ' + str(min_input_length))
sys.exit(0)

try:
test = int(e)
except:
sys.stderr.write('end timestamp is an invalid data format')
sys.exit(0)

padding = max_input_length - len(e)

if padding >  0:
for i in range(1, padding+1, 1):
e=e+'0'

except:
sys.stderr.write('error parsing input parameters')
sys.exit(0)

for line in sys.stdin:
if is_json(line):

d = j.loads(line)
dateT = d["t"]["$date"]

match_object = regex.match( r'(\d{4})([-])(\d{2})([-])(\d{2})([T])(\d{2})([:])(\d{2})([:])(\d{2})(.*)', dateT)
d_t_fmt = datetime.strptime(match_object.group(1)+match_object.group(3)\
+match_object.group(5)\
+match_object.group(7)+match_object.group(9)
+match_object.group(11), '%Y%m%d%H%M%S')

match_object = regex.match( r'(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})',  b)

try:
start_d_t_fmt = datetime.strptime(match_object.group(1)+match_object.group(2)\
+match_object.group(3)\
+match_object.group(4)+match_object.group(5)
+match_object.group(6), '%Y%m%d%H%M%S')
except:
sys.stderr.write('error converting start date-time to a datatime format')

match_object = regex.match( r'(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})',  e)

try:
end_d_t_fmt = datetime.strptime(match_object.group(1)+match_object.group(2)\
+match_object.group(3)\
+match_object.group(4)+match_object.group(5)
+match_object.group(6), '%Y%m%d%H%M%S')
except:
sys.stderr.write('error converting end date-time to a datatime format')

if (start_d_t_fmt = d_t_fmt) and not regex.match(r'^$', line):
print(line,end="")

sys.stdin.close()

except OSError as err:
print('!!! ',err)
Похоже, что все мои исследования указывают на именование каталогов в Windows, хотя я не пишу ни в какие файлы


Подробнее здесь: https://stackoverflow.com/questions/786 ... ame-stdout
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»