New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 incompatibility when signing #495

Closed
msimacek opened this Issue Dec 4, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@msimacek
Contributor

msimacek commented Dec 4, 2017

After switching to python 3, my code started to crash with:

  File "/usr/lib/python3.6/site-packages/koschei/plugins/fedmsg_plugin/backend/publisher.py", line 31, in publish_fedmsg
    fedmsg.publish(**message)
  File "/usr/lib/python3.6/site-packages/fedmsg/__init__.py", line 81, in _wrapper
    return func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/fedmsg/__init__.py", line 93, in publish
    return __local.__context.publish(topic, msg, **kw)
  File "/usr/lib/python3.6/site-packages/fedmsg/core.py", line 328, in publish
    [topic, fedmsg.encoding.dumps(msg).encode('utf-8')],
  File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/site-packages/fedmsg/encoding/__init__.py", line 73, in default
    return super(FedMsgEncoder, self).default(obj)
  File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

There are no bytes in my message, so I tried to run it with a debugger and print the message right before it fails (long values replaced by ....):

{'certificate': b'....',
 'crypto': 'x509',
 'i': 1,
 'msg': {'collection': 'f27',
  'collection_name': 'Fedora Rawhide',
  'groups': [],
  'koji_instance': 'primary',
  'name': 'net-snmp',
  'new': 'failing',
  'old': 'ok',
  'repo': 'f27'},
 'msg_id': '2017-065efb41-59ac-4285-abb5-8d7d91e9f260',
 'signature': b'....',
 'timestamp': 1512397293,
 'topic': 'org.fedoraproject.stg.koschei.package.state.change',
 'username': 'koschei'}

As you can see, the certificate and signature keys are of type bytes, which makes the json encoder fail.

fedmsg version: fedmsg-1.0.1-4.fc27.noarch

CC @mizdebsk

@jeremycline jeremycline added the bug label Dec 4, 2017

jeremycline added a commit to jeremycline/fedmsg that referenced this issue Dec 7, 2017

Adjust the x509 signing API to return text instead of bytes
Instead of returning ascii-encoded bytes, return the signature and
certificate as text so it can be JSON-serialized in Python 3.

fixes fedora-infra#495

Signed-off-by: Jeremy Cline <jeremy@jcline.org>

jeremycline added a commit to jeremycline/fedmsg that referenced this issue Dec 8, 2017

Adjust the x509 signing API to return text instead of bytes
Instead of returning ascii-encoded bytes, return the signature and
certificate as text so it can be JSON-serialized in Python 3.

fixes fedora-infra#495

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
@msimacek

This comment has been minimized.

Contributor

msimacek commented Dec 22, 2017

Could you, please, make a release with this fix? It's blocking us from migrating Koschei to Python 3

@jeremycline

This comment has been minimized.

Member

jeremycline commented Jan 2, 2018

Sorry, it got lost in the shuffle. I've tagged a release and it's on PyPI. Fedora builds are going now.

@msimacek

This comment has been minimized.

Contributor

msimacek commented Jan 25, 2018

When can we expect it in stable (and thus in infra)?

@jeremycline

This comment has been minimized.

Member

jeremycline commented Jan 25, 2018

I was just waiting for some additional testing, thanks for doing that! I've submitted it for the next batch update, so Wednesday. If you need it sooner you could always tag it into f27-infra as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment