500 error only on root page at IP address (api key problem?)

Hi, I’ve managed to get Kegberry installed on a Model B Raspberry Pi. At first, I tried a clean raspbian install with the curl command for the install, but i ran into issues with it frequently locking up. I’ve updated the SD card, and still had similar issues, so I re-imaged the new card with the kegberry image.

I was able to run through the web setup, and add my first keg to the database, but then I started to get 504 errors when accessing the web server.

I have not turned off the debugging or fixed the email. Could that be causing this issue?..I figured out that I have to change to the kegberry user (not kegbot as it says in the instructions), but I don’t know what the password is.

Thanks in advance,

-Aaron

Is this by chance a 256 MB RPi? (Paste the output of cat /proc/meminfo if you’re not sure.)

The following helped me turn off Debug and edit the E-mail settings…

sudo su - kegberry
nano ~/.kegbot/local_settings.py

After making the change, the server operated smoothly for a while, but the error returned. I’m rebooting to see if it it’ll start up again okay.

It’s the original model B.

Here’s the output…

MemTotal:         188100 kB
MemFree:           10540 kB
Buffers:             180 kB
Cached:             2740 kB
SwapCached:        14868 kB
Active:            80532 kB
Inactive:          81768 kB
Active(anon):      79672 kB
Inactive(anon):    79752 kB
Active(file):        860 kB
Inactive(file):     2016 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        102396 kB
SwapFree:          22880 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        146236 kB
Mapped:             1116 kB
Shmem:                20 kB
Slab:               5724 kB
SReclaimable:       1952 kB
SUnreclaim:         3772 kB
KernelStack:         968 kB
PageTables:         2104 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      196444 kB
Committed_AS:     707464 kB
VmallocTotal:     827392 kB
VmallocUsed:         932 kB
VmallocChunk:     588268 kB

I’m currently getting ‘server error (500)’

We haven’t had chance to do much testing on the original (256mb) model B. I suspect scarce memory is leading the system to thrash and timeout serving requests.

Thanks for the update. So it’s a bit over 24 hours later and I wanted to report. I was having the same error so I decided to move the root filesystem to a usb stick.

Following the instructions here, I was able to get the gist of how to do this.

http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=44177

I did not follow the directions exactly. For moving the partition, I actually used gparted on a separate linux machine. Near the end, he includes instructions on how to change the linux swapfile size. I made the size 256mb – I also had to kill celery and redis-server to free up enough RAM to allow me to made the changes to the swap file.

Performance has definitely improved, at the command line and in the web interface.

I’m testing it out by taxing the server…uploading image files for beers and users (this crashed it before) with mixed results. I ended up getting a 500 error on the main page after uploading a new image for a beer but strangely, I was able to access other pages, but not the main dashboard…and unlike before this remained persistent after the reboot (I can see the new beer – which was strangely duplicated).

At this point, I’m getting tempted install the server on my netbook instead.

So, it’s still running with increased RAM (well, increased swapspace anyway) and I was able to update/upgrade raspbian and kegbot from the command line. Through the browser, I can access every page EXCEPT the dashboard where I’m getting a 500 server error.

The kegbot logs are giving the following error:

 Traceback (most recent call last):
  File "/home/kegberry/kegbot-server.venv/local/lib/python2.7/site-packages/pykeg/web/api/middleware.py", line 72, in process_view
    util.check_api_key(request)
  File "/home/kegberry/kegbot-server.venv/local/lib/python2.7/site-packages/pykeg/web/api/util.py", line 64, in check_api_key
    raise kbapi.NoAuthTokenError('The parameter "api_key" is required')
NoAuthTokenError: The parameter "api_key" is required

So I should clarify. It’s not the dashboard page that’s the problem. The link to dashboard brings up my.ip.address/kegadmin. The only page that does not appear in the browser is the root home page at my.ip.address.

Here’s the full error:

Oct 6 2014, 1:40 a.m. (pykeg.web.api.util) NoAuthTokenError: The parameter "api_key" is required
    Traceback (most recent call last):
      File "/home/kegberry/kegbot-server.venv/local/lib/python2.7/site-packages/pykeg/web/api/middleware.py", line 72, in process_view
        util.check_api_key(request)
      File "/home/kegberry/kegbot-server.venv/local/lib/python2.7/site-packages/pykeg/web/api/util.py", line 64, in check_api_key
        raise kbapi.NoAuthTokenError('The parameter "api_key" is required')
    NoAuthTokenError: The parameter "api_key" is required

So I tracked the two errors to this one in util.py:

def check_api_key(request):
    """Check a request for an API key."""
    keystr = request.META.get('HTTP_X_KEGBOT_API_KEY')
    if not keystr:
        keystr = request.REQUEST.get('api_key')
    if not keystr:
        raise kbapi.NoAuthTokenError('The parameter "api_key" is required')

    try:
        api_key = models.ApiKey.objects.get(key=keystr)
    except models.ApiKey.DoesNotExist:
        raise kbapi.BadApiKeyError('API key does not exist')

    if not api_key.is_active():
        raise kbapi.BadApiKeyError('Key and/or user is inactive')

    # TODO: remove me.
    if api_key.user and (not api_key.user.is_staff and not api_key.user.is_superuser):
        raise kbapi.PermissionDeniedError('User is not staff/superuser')

…and this one in middleware.py:

class ApiRequestMiddleware:
    def process_view(self, request, view_func, view_args, view_kwargs):
        request.is_kb_api_request = util.is_api_request(request)
        if not request.is_kb_api_request:
            # Not an API request. Skip me.
            return None

        try:
            if request.need_setup:
                raise ValueError('Setup required')
            elif request.need_upgrade:
                raise ValueError('Upgrade required')

            need_auth = util.needs_auth(view_func)
            privacy = request.kbsite.privacy
            if request.path.startswith(WHITELISTED_API_PATHS):
                # API request to whitelisted path.
                need_auth = False
            else:
                # API request to non-whitelisted path, in non-public site privacy mode.
                # Demand API key.
                if privacy == 'members' and not request.user.is_authenticated():
                    need_auth = True
                elif privacy == 'staff' and not request.user.is_staff:
                    need_auth = True

            if need_auth:
                util.check_api_key(request)

            return None

        except Exception, e:
            return util.wrap_exception(request, e)

…so it seems like something’s wrong with the api key…but it appears when i log in…any ideas?