arthurk / django-disqus

Integrates DISQUS into Django
http://django-disqus.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
326 stars 101 forks source link

disqus_export HTTP 400: Bad Request #10

Open kogan opened 13 years ago

kogan commented 13 years ago

I was getting a HTTP 400 Bad Request when exporting my django.contrib.comments. This was because the export command was not properly assigning the default value when the contrib model returned an empty string for User and User Email.

I fixed it by modifying the disqus_export.py file to perform the following tests: author_email = 'nobody@nobody.org' if not author_email else author_email author_name = 'nobody' if not author_name else author_name

that segment of code then looked like:

        # name and email are optional in contrib.comments but required
        # in DISQUS. If they are not set, dummy values will be used
        author_email = comment.userinfo.get('email', '')
        author_email = 'nobody@nobody.org' if not author_email else author_email
        author_name = comment.userinfo.get('name', '')
        author_name = 'nobody' if not author_name else author_name

        client.create_post(
            forum_api_key=forum_api_key,
            thread_id=thread['id'],
            message=comment.comment.encode('utf-8'),
            author_name=author_name.encode('utf-8'),
            author_email=author_email.encode('utf-8'),
            author_url=comment.userinfo.get('url', ''),
            created_at=comment.submit_date.strftime('%Y-%m-%dT%H:%M'))
        if state_file is not None:
            self._save_state(state_file, comment.pk)
tylerball commented 13 years ago

Thank you. you are a god!

peppelorum commented 13 years ago

This solves this issue partly. I ran into an issue when first exporting from Posterous to Django comments and then to Disqus, cause email is empty (or ''), so email is there but it's empty. So I made an extra check just to make sure it really is there, something like:

email = author_email.encode('utf-8') if len(email) < 1: email = 'nobody@nobody.org'

derekjamescurtis commented 10 years ago

I realize this was 3+ years ago, but if you still have the code, it would be SUPER nice to get it in a pull request so we could include it in the next release.