Skip to content

logging.handlers.DatagramHandler sends bad data to socketserver.DatagramRequestHandler #81512

Description

@yoonghm
mannequin
BPO 37331
Nosy @vsajip, @yoonghm
PRs
  • bpo-37331: Clarify format of socket handler messages in the documenta… #14234
  • [3.8] bpo-37331: Clarify format of socket handler messages in the documentation. (GH-14234) #14235
  • [3.7] bpo-37331: Clarify format of socket handler messages in the documentation. (GH-14234) #14236
  • Files
  • attachment.md: UDP server receive for syslog message
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-06-19.14:43:45.926>
    created_at = <Date 2019-06-18.19:37:02.385>
    labels = ['3.8', 'type-bug', '3.7', '3.9', 'docs']
    title = 'logging.handlers.DatagramHandler sends bad data to socketserver.DatagramRequestHandler'
    updated_at = <Date 2019-06-19.14:43:45.925>
    user = 'https://github.com/yoonghm'

    bugs.python.org fields:

    activity = <Date 2019-06-19.14:43:45.925>
    actor = 'vinay.sajip'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-06-19.14:43:45.926>
    closer = 'vinay.sajip'
    components = ['Documentation']
    creation = <Date 2019-06-18.19:37:02.385>
    creator = 'yoonghm'
    dependencies = []
    files = ['48426']
    hgrepos = []
    issue_num = 37331
    keywords = ['patch']
    message_count = 6.0
    messages = ['346005', '346020', '346048', '346050', '346052', '346053']
    nosy_count = 3.0
    nosy_names = ['vinay.sajip', 'docs@python', 'yoonghm']
    pr_nums = ['14234', '14235', '14236']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37331'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. yoonghm commented on Jun 18, 2019

      yoonghmmannequin
      MannequinAuthor

      pysyslog.py

      • A UDP server listens at 0.0.0.0:514 for syslog messages.

      syslogmsg_gen.py

      • Send syslog message to local syslog server via 127.0.0.1:514

      Error:

      Exception has occurred: UnicodeDecodeError
      'utf-8' codec can't decode byte 0xd7 in position 381: invalid continuation byte
      File "C:\pysyslog.py", line 21, in handle
      data = self.request[0].decode('utf-8')
      File "C:\pysyslog.py", line 28, in <module>
      server.serve_forever(poll_interval=0.5)

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jun 18, 2019
    3. yoonghm commented on Jun 19, 2019

      yoonghmmannequin
      MannequinAuthor

      I did some checks, I discovered the following:

      logging.handlers.DatagramHandler() sends data in the following format:

      1. message length
      2. message itself which consists of
        a. Creation time in ASCII format
        b. Creation time in seconds, ms
        c. Filename, line no
        d. Message level
        e. Message
        f. Logger name
        etc.

      Item 1. is packed using struct.pack(">L")
      Item 2. is packed using pickle

      The message format is not mentioned in any of the standard Python document. Also it may not be compatible with third-party syslog message library or generator.

    4. vsajip commented on Jun 19, 2019

      @vsajip
      Member

      It is mentioned here:

      https://docs.python.org/3/library/logging.handlers.html?highlight=datagramhandler#logging.handlers.SocketHandler.makePickle

      although that doesn't go into the detail of the struct.pack format. I'll update the documentation to rectify this.

    5. added
      docsDocumentation in the Doc dir
      and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Jun 19, 2019
    6. vsajip commented on Jun 19, 2019

      @vsajip
      Member

      New changeset f06b569 by Vinay Sajip in branch 'master':
      bpo-37331: Clarify format of socket handler messages in the documentation. (GH-14234)
      f06b569

    7. vsajip commented on Jun 19, 2019

      @vsajip
      Member

      New changeset b64e42e by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
      bpo-37331: Clarify format of socket handler messages in the documentation. (GH-14234) (GH-14236)
      b64e42e

    8. vsajip commented on Jun 19, 2019

      @vsajip
      Member

      New changeset d7232f0 by Vinay Sajip (Miss Islington (bot)) in branch '3.8':
      bpo-37331: Clarify format of socket handler messages in the documentation. (GH-14234) (GH-14235)
      d7232f0

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifedocsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions