isso-comments / isso

a Disqus alternative
https://isso-comments.de
MIT License
5.03k stars 440 forks source link

When commenting, clicking submit causes errors #159

Closed xuhdev closed 9 years ago

xuhdev commented 9 years ago

I posted this issue on the mailing list, but it seems no one is there...

I installed isso on my site recently, but whenever I tried to comment, I can see the following error in the log:

ERROR: POST /new
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/isso/__init__.py", line 133, in dispatch
    response = handler(request.environ, request, **values)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/comments.py", line 84, in dec
    return func(self, env, req, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/__init__.py", line 45, in dec
    return func(cls, env, req, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/comments.py", line 218, in new
    value=self.isso.sign([rv["id"], sha1(rv["text"])]),
  File "/usr/local/lib/python2.7/dist-packages/isso/__init__.py", line 114, in sign
    return self.signer.dumps(obj)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 566, in dumps
    rv = self.make_signer(salt).sign(payload)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 412, in sign
    return value + sep + self.get_signature(value)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 347, in get_signature
    key = self.derive_key()
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 334, in derive_key
    self.secret_key).digest()
TypeError: cannot concatenate 'str' and 'buffer' objects

The comments were still be sent, but no notification will be received, with neither smtp or stdout notifier.

Does anyone know why this happened?

posativ commented 9 years ago

Sorry, been busy. Can you try downgrading itsdangerous to version 0.23 via

$ pip uninstall itsdangerous
$ pip install itsdangerous==0.23

and see if this error happens as well? Also, what is your $LANG and environment in general?

xuhdev commented 9 years ago

Downgrading does not do any good. $LANG is empty.

posativ commented 9 years ago

Does it also happen if you start Isso via env LANG=en_US.UTF-8 isso [...]?

xuhdev commented 9 years ago

@posativ I tried but still the same error... Is this an issue in itsdangerous?

xuhdev commented 9 years ago

I also have this warning maybe they are related:

WARNING: no such option: [hash] salt
WARNING: no such option: [hash] algorithm
posativ commented 9 years ago

It is unrelated to the new hash section (which is only available in the master). Can you paste pip freeze along with a sample comment, that causes this error? Also, I'm interested in your environment as it might be caused by a wrong locale.

The comment is actually saved, but only because the exception happens afterwards when a signed cookie is issued (so if you submit the comment, you need to refresh manually, because the comment creation actually fails).

It might be fixed in the master branch, because I've rewritten handling of hash functions and added type safety.

xuhdev commented 9 years ago

pip freeze outputs:

Warning: cannot find svn location for distribute==0.6.24dev-r0
Werkzeug==0.9.6
argparse==1.2.1
configparser==3.3.0r2
## FIXME: could not find svn URL in dependency_links for this package:
distribute==0.6.24dev-r0
gevent==1.0.1
greenlet==0.4.3
gunicorn==19.1.0
html5lib==1.0b3
ipaddr==2.1.11
isso==0.9.5
itsdangerous==0.24
medusa==0.5.4
meld3==0.6.5
misaka==1.0.2
six==1.7.3
supervisor==3.0a8
wsgiref==0.1.2

Yes the comment is actually saved. The test comment is shown in this page as this is a test. In the sqlite database, this is the corresponding line in the comments table

12|125||1423005801.80556||1|2605:e000:150f:0000:0000:0000:0000:0000|this is a test||||0|0|
xuhdev commented 9 years ago

It's strange the version is still 0.9.5.. I'll do an upgrade

xuhdev commented 9 years ago

OK, I've upgraded to the master version of isso, but problem still persists:

Werkzeug==0.10.1
argparse==1.2.1
chardet==2.0.1
colorama==0.2.5
configparser==3.3.0r2
gevent==1.0.1
greenlet==0.4.5
gunicorn==19.2.0
html5lib==0.999
ipaddr==2.1.11
isso==0.10.dev0
itsdangerous==0.24
meld3==0.6.10
misaka==1.0.2
requests==2.2.1
six==1.5.2
ssh-import-id==3.21
supervisor==3.0b2
urllib3==1.7.1
wsgiref==0.1.2
posativ commented 9 years ago

Can you paste the stacetrack when using the master version of Isso?

xuhdev commented 9 years ago
ERROR: POST /new
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/isso/__init__.py", line 132, in dispatch
    response = handler(request.environ, request, **values)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/comments.py", line 67, in dec
    return func(self, env, req, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/__init__.py", line 45, in dec
    return func(cls, env, req, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/isso/views/comments.py", line 197, in new
    value=self.isso.sign([rv["id"], sha1(rv["text"])]),
  File "/usr/local/lib/python2.7/dist-packages/isso/__init__.py", line 113, in sign
    return self.signer.dumps(obj)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 566, in dumps
    rv = self.make_signer(salt).sign(payload)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 412, in sign
    return value + sep + self.get_signature(value)
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 347, in get_signature
    key = self.derive_key()
  File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 334, in derive_key
    self.secret_key).digest()

They seems to be the same...

xuhdev commented 9 years ago

Is there any chance to fix it...

posativ commented 9 years ago

Assuming you run Isso from the command-line, what is your env? I don't know what's wrong, but it seems there is an encoding issue.

xuhdev commented 9 years ago

"env" outputs:

XDG_CONFIG_DIRS=/etc/xdg
LANG=en_US.utf8
DISPLAY=:0
SHLVL=4
CLOJURE_HOME=/usr/share/clojure
XDG_VTNR=1
HG=/usr/bin/hg
MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins
XAUTHORITY=/var/run/gdm/auth-for-hong-NViTUw/database
PWD=/home/hong/tmp/isso
MAVEN_OPTS=-Xmx512m
GTK_IM_MODULE=fcitx
ANT_HOME=/usr/share/apache-ant
XDG_SESSION_ID=c2
DESKTOP_SESSION=xfce
XDG_SESSION_DESKTOP=xfce
GDMSESSION=xfce
USERNAME=hong
WINDOWPATH=1
ANDROID_SWT=/usr/share/java
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-yNHVNEF1BX,guid=0ecf2fe45dbb2c1bf5a055d554e51da4
VTE_VERSION=3803
MAIL=/var/spool/mail/hong
_=/usr/bin/env
XDG_DATA_DIRS=/usr/local/share:/usr/share
XDG_MENU_PREFIX=xfce-
GLADE_MODULE_PATH=:
SHELL=/bin/zsh
QT_IM_MODULE=fcitx
GRADLE_HOME=/usr/share/java/gradle
USER=hong
WINDOWID=58720266
TERM=xterm-256color
SSH_AGENT_PID=4101
GTK_MODULES=canberra-gtk-module
GLADE_CATALOG_PATH=:
SESSION_MANAGER=local/home.hong.me:@/tmp/.ICE-unix/4108,unix/home.hong.me:/tmp/.ICE-unix/4108
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
MATHEMATICA_HOME=/opt/Wolfram/Mathematica/10.0
HOME=/home/hong
XDG_SEAT=seat0
GLADE_PIXMAP_PATH=:
PATH=/home/hong/tmp/isso/bin:/home/hong/.emacs.d/el-get/rtags/bin:/home/hong/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/depot-tools-git:/usr/share/java/gradle/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/hong/.local/bin
XDG_RUNTIME_DIR=/run/user/1000
XMODIFIERS=@im=fcitx
ANDROID_HOME=/opt/android-sdk
OLDPWD=/home/hong/tmp/isso/isso
LESS_TERMCAP_mb=
LESS_TERMCAP_md=
LESS_TERMCAP_me=
LESS_TERMCAP_se=
LESS_TERMCAP_so=
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
GREP_COLOR=37;45
GREP_COLORS=mt=37;45
INCLUDE=/home/hong/.local/include
C_INCLUDE_PATH=/home/hong/.local/include
CPLUS_INCLUDE_PATH=/home/hong/.local/include
LIBRARY_PATH=/home/hong/.local/lib
LD_LIBRARY_PATH=/home/hong/.local/lib
EDITOR=vim -f
MAKEFLAGS=-j7
VIRTUAL_ENV=/home/hong/tmp/isso
xuhdev commented 9 years ago

@posativ I've modified the code to print some of the variables near the place where the error occurs. Here is the modification I made, basically just print out everything relavant (modified here):

        try:
            handler, values = adapter.match()
            print('request.environ: ')
            print(request.environ)
            print('----')
            print('request: ')
            print(request)
            print('----')
            print('values: ')
            print(values)
            print('----')
        except HTTPException as e:
            return e
        else:
            try:
                response = handler(request.environ, request, **values)
            except HTTPException as e:
                return e
            except Exception:
                print('(Non-HTTP) Exception occurs!!!')
                print('=======')
                logger.exception("%s %s", request.method, request.environ["PATH_INFO"])
                return InternalServerError()
            else:
                return response
        print('=======')

The output where the error occurs

request.environ:
{'wsgi.multiprocess': False, 'HTTP_REFERER': 'http://localhost:8000/blog/2014/10/13/install-php-extensions-on-shared-hosts/', 'SERVER_SOFTWARE': 'Werkzeug/0.10.1', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'POST', 'PATH_INFO': '/new', 'HTTP_ORIGIN': 'http://localhost:8000', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING': 'uri=%2Fblog%2F2014%2F10%2F13%2Finstall-php-extensions-on-shared-hosts%2F', 'werkzeug.server.shutdown': <function shutdown_server at 0x7ff320a25e60>, 'werkzeug.proxy_fix.orig_wsgi_url_scheme': 'http', 'CONTENT_LENGTH': '84', 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': '_ga=GA1.1.429151845.1423771241; _pk_id.1.1fff=322cd312224054a6.1423771242.5.1424334919.1424329074.; _pk_ses.1.1fff=*', 'SERVER_NAME': '0.0.0.0', 'REMOTE_PORT': 36515, 'wsgi.url_scheme': 'http', 'SERVER_PORT': '7000', 'werkzeug.proxy_fix.orig_http_host': 'localhost:7000', 'werkzeug.request': <JSONRequest 'http://localhost:7000/new?uri=%2Fblog%2F2014%2F10%2F13%2Finstall-php-extensions-on-shared-hosts%2F' [POST]>, 'wsgi.input': <socket._fileobject object at 0x7ff31d89a4d0>, 'werkzeug.proxy_fix.orig_remote_addr': '127.0.0.1', 'HTTP_HOST': 'localhost:7000', 'wsgi.multithread': True, 'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'wsgi.run_once': False, 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7ff327f6e1e0>, 'REMOTE_ADDR': '127.0.0.1', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4', 'CONTENT_TYPE': 'application/json', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate'}
----
request:
<JSONRequest 'http://localhost:7000/new?uri=%2Fblog%2F2014%2F10%2F13%2Finstall-php-extensions-on-shared-hosts%2F' [POST]>
----
values:
{}
----
(Non-HTTP) Exception occurs!!!
======= 

The complete output (include those without any errors) is available here