Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7989581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:47:34+00:00 2026-06-04T12:47:34+00:00

I have a weird error in my flask application. Problem is that the code

  • 0

I have a weird error in my flask application.
Problem is that the code below works fine in the Flask development server but fails in the production server (Uwsgi+Nginx). The code’s intention is to retrieve an entire collection from mongoDb and serve it’s contents as JSON.

I am not using virtualenv as I work under a virtual machine and also, I don’t have any other projects running on that machine.
So the stack is like this:

Python
Flask
MongoDb->MongoEngine
Uwsgi
NginX

I have two models:

One for Company:

class Company(Document):
    name = StringField(max_length=50)
    ....

One for Campaigns:

class Campaign(Document):
    name = StringField(min_length=8)
    company = ReferenceField(Company)
    ....

The routing is done like this:

@app.route('/getjson', methods=['GET', 'POST'])
    def getJson():
        if request.method == 'GET':
        collection = request.args.get('collection')
        if collection == 'Campaign':
            return jsonify (getCampaign())

And the getCampaign() function goes like this:

def getCampaign():
    theCollection = Campaign.objects.all()
    theDict = {}
    for obj in x:
        dict_model = {
            obj.name:
            {
            'company': obj.company.name,
            ...
            }
    theDict.update(dict_model)
return theDict

This results in a nicely formated Json with “application/json” as Content-Type. Problem is when o try the same code on the production server it fails miserably throwing the following error!

    Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1518, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1506, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1504, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1264, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1262, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1248, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./mobuy.py", line 58, in getJson
    return jsonify (getCampaign())
  File "./jsonOut.py", line 36, in getCampaign
    'company': obj.company.name,
  File "/usr/local/lib/python2.6/dist-packages/bson/dbref.py", line 88, in __getattr__
     raise AttributeError(key)
  AttributeError: name

Running ” ‘company’: “%s” % obj.dict ” throws this result:

"company":"{'_created': False, '_data': {'status': 3, 'startDate':
datetime.datetime(2012, 5, 23, 20, 22, 28, 42000), None: ObjectId('4fbd4704f65b813c5900000d'), 
'EndDate': datetime.datetime(2012, 5, 23, 20, 22, 28, 42000), 
'name': u'Campaign13', 'max_claimed': 39, 'text': u'a discount', 
'company': DBRef(u'company', ObjectId('4fbd36f2f65b813869000008')),
'image': u'http://www.Company8.com/image.jpg', 'Shops': [],
 'category': 5, 'id': None, 'coupons': []},
 '_id': ObjectId('4fbd4704f65b813c5900000d'), '_changed_fields': [],
 '_initialised': True}",

HELP! Why is this working in dev server and not working in Uwsgi??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:47:35+00:00Added an answer on June 4, 2026 at 12:47 pm

    The solution i found is, i went around the problem and queried the database with pymongo directly

    #init pymongo dor dbfer quering as uwsgi fails miserably
    connection = Connection()
    db = connection.mobuy_test
    company_collection = db.company
    campaign_collection = db.campaign
    for obj in Campaign.objects.all(): #the mongoengine queryset loop
        theId = campaign_collection.find_one({'_id':obj.id})['company'].id
        companyName = company_collection.find_one({'_id':theId})['name']
        dict_model = {
                      'campaign_name': obj.name,
                      'campaign_company':companyName
                       ...
                      }
    

    Not sure if i used the pymongo query correctly but this works for now, only problem is, It’s Dirty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having an weird problem, my project have a login page, that's working, but
I'm building a simple FB application but I'm getting a weird error. I have
I have weird problem with this code: if I run it like shown below
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have a weird problem that i can't figure out a solution for: I've
Hey guys I have a weird error I wrote this code against setbubblepopup $(document).ready(function
I have a weird error in my code. I'm trying to read some characters
I have a weird error that I cannot seem to find any documentation or
I have had that weird error this afternoon... I cannot figure out why System.Data
I am making a web application. I have gotten a weird error with update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.