abhishek-ram / pyas2

This repo is no longer maintained and has been moved to https://github.com/abhishek-ram/django-pyas2
GNU General Public License v2.0
47 stars 23 forks source link

Getting Python error when trying to send message #43

Closed rcloudprojekt closed 6 years ago

rcloudprojekt commented 7 years ago

Hello,

I installed 2 pyas2 server and configured them based on the documentation.

When I try to send Messages I get the same error on both systems shown in the logs:

20171108 08:00:19 ERROR : Failed to send message, error: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pyas2/management/commands/sendas2message.py", line 73, in handle as2lib.send_message(message, payload) File "/usr/local/lib/python2.7/dist-packages/pyas2/as2lib.py", line 459, in send_message u'command "retryfailedas2comms".' % e)) TypeError: str returned non-string (type Error)

Any Idea to what would cause this?

Thank you.

Alex

abhishek-ram commented 7 years ago

Can you send me list of packages installed with their versions

rcloudprojekt commented 7 years ago

Hi,

Thank you getting back to me I used pip and got the following list.

CherryPy==8.9.1 Django==1.10.6 Flask==0.10.1 Jinja2==2.7.3 M2Crypto==0.26.0 MarkupSafe==0.23 MySQL-python==1.2.3 Pillow==2.6.1 RPi.GPIO==0.6.3 RTIMULib==7.2.1 Werkzeug==0.9.6 argparse==1.2.1 blinker==1.3 chardet==2.3.0 colorama==0.3.2 gpiozero==1.3.2 html5lib==0.999 itsdangerous==0.24 lxkeymap==0.1 mcpi==0.1.1 ndg-httpsclient==0.3.2 numpy==1.8.2 picamera==1.13 picraft==1.0 pifacecommon==4.2.1 pifacedigitalio==3.1.0 pigpio==1.35 pyAS2==0.3.3 pyOpenSSL==0.13.1 pyasn1==0.1.7 pygame==1.9.2a0 pygobject==3.14.0 pyinotify==0.9.4 pyserial==2.6 python-apt==0.9.3.12 requests==2.4.3 sense-emu==1.0 sense-hat==2.2.0 six==1.8.0 smbus==1.1 spidev==3.0 twython==3.1.2 typing==3.6.1 urllib3==1.9.1 wheel==0.24.0 wsgiref==0.1.2

I just saw, that it lists PYAS2 as 3.3, should I update to 3.4? I also tried to use django-admin.py test pyas2 --settings=pyas2.test_settings --pythonpath=.

Under the user Pi I get an error due to insufficient rights to write the logs. Under the user Root the process goes through but I get the following errors. The certificate was generated with OpenSSL as described in the documentation.

Creating test database for alias 'default'...
20171108 13:33:26 INFO     : Received an AS2 message with id 20171108133326.27824.45688@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:26 INFO     : Received an AS2 message with id 20171108133326.27824.83404@raspberry_edi_lab for organization as2server from partner as2client
.20171108 13:33:26 INFO     : Received an AS2 message with id 20171108133326.27824.90063@raspberry_edi_lab for organization as2server from partner as2client
.20171108 13:33:26 INFO     : Received an AS2 message with id 20171108133326.27824.48874@raspberry_edi_lab for organization as2server from partner as2client
E20171108 13:33:27 INFO     : Received an AS2 message with id 20171108133327.27824.96899@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:27 INFO     : Received an AS2 message with id 20171108133327.27824.6571@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:27 INFO     : Received an AS2 message with id 20171108133327.27824.92891@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:28 INFO     : Received an AS2 message with id 20171108133327.27824.28192@raspberry_edi_lab for organization as2server from partner as2client
F.20171108 13:33:28 INFO     : Received an AS2 message with id 20171108133328.27824.28936@raspberry_edi_lab for organization as2server from partner as2client
.20171108 13:33:28 INFO     : Received an AS2 message with id 20171108133328.27824.40314@raspberry_edi_lab for organization as2server from partner as2client
.20171108 13:33:28 INFO     : Received an AS2 message with id 20171108133328.27824.58028@raspberry_edi_lab for organization as2server from partner as2client
E20171108 13:33:28 INFO     : Received an AS2 message with id 20171108133328.27824.34636@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:29 INFO     : Received an AS2 message with id 20171108133328.27824.5659@raspberry_edi_lab for organization as2server from partner as2client
F20171108 13:33:29 INFO     : Received an AS2 message with id 20171108133329.27824.80669@raspberry_edi_lab for organization as2server from partner as2client
F
======================================================================
ERROR: testEncryptMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 6: Sender sends encrypted data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 249, in testEncryptMessageSignMdn
    AS2SendReceiveTest.buildMdn(in_message, response)
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 568, in buildMdn
    as2lib.save_mdn(out_message, mdn_content)
  File "/usr/local/lib/python2.7/dist-packages/pyas2/as2lib.py", line 551, in save_mdn
    raise as2utils.As2Exception(_(u'MDN Signature Verification Error, exception message is %s' % e))
As2Exception: MDN Signature Verification Error, exception message is certificate verify error

======================================================================
ERROR: testNoEncryptMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 3: Sender sends un-encrypted data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 155, in testNoEncryptMessageSignMdn
    AS2SendReceiveTest.buildMdn(in_message, response)
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 568, in buildMdn
    as2lib.save_mdn(out_message, mdn_content)
  File "/usr/local/lib/python2.7/dist-packages/pyas2/as2lib.py", line 551, in save_mdn
    raise as2utils.As2Exception(_(u'MDN Signature Verification Error, exception message is %s' % e))
As2Exception: MDN Signature Verification Error, exception message is certificate verify error

======================================================================
FAIL: testCompressEncryptSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 13: Sender sends compressed, encrypted and signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 471, in testCompressEncryptSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageAsyncSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 14: Sender sends encrypted and signed data and requests an Asynchronous signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 504, in testEncryptSignMessageAsyncSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 11: Sender sends encrypted and signed data and requests an unsigned receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 401, in testEncryptSignMessageMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageNoMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 10: Sender sends encrypted and signed data and does NOT request a receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 372, in testEncryptSignMessageNoMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 12: Sender sends encrypted and signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 436, in testEncryptSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 8: Sender sends signed data and requests an unsigned receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 305, in testSignMessageMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageNoMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 7: Sender sends signed data and does NOT request a receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 278, in testSignMessageNoMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 9: Sender sends signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyas2/tests/tests.py", line 338, in testSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

----------------------------------------------------------------------
Ran 15 tests in 3.312s

FAILED (failures=8, errors=2)
Destroying test database for alias 'default'...

Thank you very much.

Alex

abhishek-ram commented 7 years ago

Please upgrade the requests library to the latest version

rcloudprojekt commented 7 years ago

I upgraded Request to 2.18.4 The error when sending a message changed. Now I got a error because the other server could not verify the certificate. I will update the second server and come back to you after.

One thing is still curious... when I run the django-admin.py test pyas2 --settings=pyas2.test_settings --pythonpath=. I still get the same errors.

rcloudprojekt commented 7 years ago

Sorry for the long break. I finally found the time to update the second server and I get the same error on both servers when I try to send a file.

I get send failed with error HTTPSConnectionPool(host='XX.XX.XXX.XX', port=8888): Max retries exceeded with url: /pyas2/as2receive (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))

This seems to be a problem related to Python 2.7.9, when you use self-signed certificates. From what I have read around, Python checks the CA and does not accept self-signed certificates.

AmaliaSoucek commented 6 years ago

Hi!

I'm getting the same MDN Signature Verification Error error when I try to run the tests. Is there any way to fix this?

Regards, Amalia

abhishek-ram commented 6 years ago

Are you transferring between 2 installations of pyas2 @AmaliaSoucek?

AmaliaSoucek commented 6 years ago

Hi,

I just created a new virtualenv (python 2.7.13) and followed the installation guide. I then run django-admin.py test pyas2 --settings=pyas2.test_settings --pythonpath=. and got the following errors:

======================================================================
ERROR: testEncryptMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 6: Sender sends encrypted data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 249, in testEncryptMessageSignMdn
    AS2SendReceiveTest.buildMdn(in_message, response)
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 568, in buildMdn
    as2lib.save_mdn(out_message, mdn_content)
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/as2lib.py", line 551, in save_mdn
    raise as2utils.As2Exception(_(u'MDN Signature Verification Error, exception message is %s' % e))
As2Exception: MDN Signature Verification Error, exception message is certificate verify error

======================================================================
ERROR: testNoEncryptMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 3: Sender sends un-encrypted data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 155, in testNoEncryptMessageSignMdn
    AS2SendReceiveTest.buildMdn(in_message, response)
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 568, in buildMdn
    as2lib.save_mdn(out_message, mdn_content)
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/as2lib.py", line 551, in save_mdn
    raise as2utils.As2Exception(_(u'MDN Signature Verification Error, exception message is %s' % e))
As2Exception: MDN Signature Verification Error, exception message is certificate verify error

======================================================================
FAIL: testCompressEncryptSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 13: Sender sends compressed, encrypted and signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 471, in testCompressEncryptSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageAsyncSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 14: Sender sends encrypted and signed data and requests an Asynchronous signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 504, in testEncryptSignMessageAsyncSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 11: Sender sends encrypted and signed data and requests an unsigned receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 401, in testEncryptSignMessageMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageNoMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 10: Sender sends encrypted and signed data and does NOT request a receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 372, in testEncryptSignMessageNoMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testEncryptSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 12: Sender sends encrypted and signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 436, in testEncryptSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 8: Sender sends signed data and requests an unsigned receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 305, in testSignMessageMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageNoMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 7: Sender sends signed data and does NOT request a receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 278, in testSignMessageNoMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

======================================================================
FAIL: testSignMessageSignMdn (pyas2.tests.tests.AS2SendReceiveTest)
Test Permutation 9: Sender sends signed data and requests an signed receipt.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/amalia/.pyenv/versions/2.7.13/envs/venv/lib/python2.7/site-packages/pyas2/tests/tests.py", line 338, in testSignMessageSignMdn
    self.assertEqual(out_message.status, 'S')
AssertionError: u'E' != 'S'

My virtualenv:

certifi==2017.11.5
chardet==3.0.4
CherryPy==8.9.1
Django==1.10.6
idna==2.6
M2Crypto==0.27.0
pyAS2==0.3.4
pyasn1==0.4.2
requests==2.18.4
six==1.11.0
typing==3.6.2
urllib3==1.22

Thank you for your help! Amalia

abhishek-ram commented 6 years ago

The issue was that the test certificates had expired :). I released a new version go ahead and update it, the tests will now work.

AmaliaSoucek commented 6 years ago

Thank you very much!