abertschi / postcards

A CLI for the Swiss Postcard Creator :postbox:
https://abertschi.ch/blog/2022/receiving-postcards/
MIT License
36 stars 8 forks source link

postcards (CRITICAL): can not send postcard: error in request #25

Closed matbech closed 6 years ago

matbech commented 6 years ago

I'm using the latest version (0.0.8) and I get the following error:

postcards (INFO): uploading postcard to server
postcards (CRITICAL): can not send postcard: error in request put https://postcardcreator.post.ch/rest/2.2/users/<censored1>/mailings/<censored2>/pages/2. status_code: 400
Traceback (most recent call last):
  File "c:\users\mb\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mb\AppData\Local\Programs\Python\Python36\Scripts\postcards.exe\__main__.py", line 9, in <module>
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 510, in main
    p.main(sys.argv)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 52, in main
    self.do_command_send(args)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 114, in do_command_send
    cli_args=args)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 123, in send_cards
    cli_args=cli_args)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 146, in send_card
    raise e
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 143, in send_card
    self.delegate_send_free_card(pcc_wrapper, card, mock_send=mock)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcards\postcards.py", line 154, in delegate_send_free_card
    pcc_wrapper.send_free_card(postcard=postcard, mock_send=mock_send)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcard_creator\postcard_creator.py", line 255, in wrapped
    return func(*args, **kwargs)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcard_creator\postcard_creator.py", line 334, in send_free_card
    self._set_svg_page(2, user_id, card_id, postcard.get_backpage())
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcard_creator\postcard_creator.py", line 387, in _set_svg_page
    return self._do_op('put', endpoint, data=svg_content, headers=headers)
  File "c:\users\mb\appdata\local\programs\python\python36\lib\site-packages\postcard_creator\postcard_creator.py", line 292, in _do_op
    raise e
postcard_creator.postcard_creator.PostcardCreatorException: error in request put https://postcardcreator.post.ch/rest/2.2/users/<censored1>/mailings/<censored2>/pages/2. status_code: 400
abertschi commented 6 years ago

I can't reproduce your error. I just tested the endpoints they respond correctly.

matbech commented 6 years ago

I tried it with different pictures and different text messages. Is there an option where the application writes the server responses to a file? Maybe there is some human readable error message in the 400 response.

abertschi commented 6 years ago

Yes, there is.

You can add -v flags before specifying the command. The more vs the more verbose the log messages. (see --help option before specifying a command).

postcards-chuck-norris -vvvvv send --config config.json --key

Error codes 400 indicate invalid text in either message payload or sender/recipient fields.

abertschi commented 6 years ago

I currently do some basic unicode data encoding only for the text message.

If your sender/recipient fields contain some non ascii characters you likely run into issues there. Also the Postal service backend can't handle emojis.

matbech commented 6 years ago

The request sent by the client was syntactically incorrect.

> HTTP/1.1 400 Bad Request
> Server: nginx/1.11.10
> Date: Wed, 02 May 2018 09:03:34 GMT
> Content-Type: text/html;charset=utf-8
> Content-Length: 1029
> Connection: keep-alive
> Keep-Alive: timeout=5
> Content-Language: en
>
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.14 (Debian) - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 400 - </h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect.</u></p><hr class="line"><h3>Apache Tomcat/8.0.14 (Debian)</h3></body></html>
matbech commented 6 years ago

Right, the umlaut ü in the address caused the error. It should probably be xml character &#x encoded. Thanks.

abertschi commented 6 years ago

Error codes 400 indicate invalid text in either message payload or sender/recipient fields.

^this

Sender/recipient fields are embedded two svg files (one for the front cover and the other one for the back cover of the postcard). My guess is that you submit non-ascii characters which render the svg files invalid.

matbech commented 6 years ago

The ü is utf-8 encoded and IE didn't complain about the front side .svg. However, the postcard creator uses xml character unicode &#x encoding.

abertschi commented 6 years ago

As I stated, I don't encode other fields than the message payload.

you are welcome to submit a PR at the postcard_creator_wrapper project so that those fields are encoded as well :) /close

matbech commented 6 years ago

Please see: https://github.com/abertschi/postcard_creator_wrapper/pull/11