Cannot encode object: pymongoGet contents of a Tkinter Entry widgetHow to know if an object has an attribute in PythonDetermine the type of an object?null object in Python?ttk tkinter multiple frames/windowsHow to sort mongodb with pymongoUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)TkInter Frame doesn't load if another function is calledEntry widget row expansion in tkinterImporting Tkinter and rowspan/sticky questionCreating a variable from one class to another

Why is it easier to balance a non-moving bike standing up than sitting down?

Will generated tokens be progressively stronger when using Cathar's Crusade and Sorin, Grim Nemesis?

How does DC work with natural 20?

Prime sieve in Python

How can you guarantee that you won't change/quit job after just couple of months?

How to make clear to people I don't want to answer their "Where are you from?" question?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

Are all Ringwraiths called Nazgûl in LotR?

UK - Working without a contract. I resign and guy wants to sue me

What are the pros and cons for the two possible "gear directions" when parking the car on a hill?

How do you pronounce the letter "t" before "h"?

Do I have to explain the mechanical superiority of the player-character within the fiction of the game?

How did Gollum enter Moria?

Story about a space war, and a human prisoner of war captured by alien enemy

Get list of shortcodes from content

How to maintain a closed environment for one person for a long period of time

What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?

Why tighten down in a criss-cross pattern?

Is there a term for the belief that "if it's legal, it's moral"?

Count All Possible Unique Combinations of Letters in a Word

How to parse 「場合でも」

What is the highest voltage from the power supply a Raspberry Pi 3 B can handle without getting damaged?

Why does independence imply zero correlation?

Should the party get XP for a monster they never attacked?



Cannot encode object: pymongo


Get contents of a Tkinter Entry widgetHow to know if an object has an attribute in PythonDetermine the type of an object?null object in Python?ttk tkinter multiple frames/windowsHow to sort mongodb with pymongoUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)TkInter Frame doesn't load if another function is calledEntry widget row expansion in tkinterImporting Tkinter and rowspan/sticky questionCreating a variable from one class to another






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm fairly new to programming and basically I have no idea what I'm doing.



I'm trying to make a write simple UI that that can take an input and write it to a mongodb.



import pymongo
from tkinter import *
from tkinter import ttk

class Input:

def __init__(self, root,):

self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")

self.mydb = self.myclient["mydatabase"]

self.mycol = self.mydb["input"]

title_label = Label(root, text="input")

title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)

self.input_value = StringVar(root, value="")

self.input = ttk.Entry(root, textvariable=self.input_value)

self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)

self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)

def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)


root = Tk()

In = Input(root)

root.mainloop()


When trying to run this I get



bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>


I tried converting input_value to 'normal' string



self.input_value = str(StringVar(root, value=""))


By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.



What am I doing wrong?










share|improve this question
























  • Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

    – Neil Lunn
    Mar 25 at 7:45











  • Doing that still results in "PY_VAR0" being written to the database.

    – DracoTomes
    Mar 25 at 7:52






  • 1





    Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

    – Neil Lunn
    Mar 25 at 8:00

















0















I'm fairly new to programming and basically I have no idea what I'm doing.



I'm trying to make a write simple UI that that can take an input and write it to a mongodb.



import pymongo
from tkinter import *
from tkinter import ttk

class Input:

def __init__(self, root,):

self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")

self.mydb = self.myclient["mydatabase"]

self.mycol = self.mydb["input"]

title_label = Label(root, text="input")

title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)

self.input_value = StringVar(root, value="")

self.input = ttk.Entry(root, textvariable=self.input_value)

self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)

self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)

def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)


root = Tk()

In = Input(root)

root.mainloop()


When trying to run this I get



bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>


I tried converting input_value to 'normal' string



self.input_value = str(StringVar(root, value=""))


By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.



What am I doing wrong?










share|improve this question
























  • Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

    – Neil Lunn
    Mar 25 at 7:45











  • Doing that still results in "PY_VAR0" being written to the database.

    – DracoTomes
    Mar 25 at 7:52






  • 1





    Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

    – Neil Lunn
    Mar 25 at 8:00













0












0








0








I'm fairly new to programming and basically I have no idea what I'm doing.



I'm trying to make a write simple UI that that can take an input and write it to a mongodb.



import pymongo
from tkinter import *
from tkinter import ttk

class Input:

def __init__(self, root,):

self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")

self.mydb = self.myclient["mydatabase"]

self.mycol = self.mydb["input"]

title_label = Label(root, text="input")

title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)

self.input_value = StringVar(root, value="")

self.input = ttk.Entry(root, textvariable=self.input_value)

self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)

self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)

def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)


root = Tk()

In = Input(root)

root.mainloop()


When trying to run this I get



bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>


I tried converting input_value to 'normal' string



self.input_value = str(StringVar(root, value=""))


By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.



What am I doing wrong?










share|improve this question
















I'm fairly new to programming and basically I have no idea what I'm doing.



I'm trying to make a write simple UI that that can take an input and write it to a mongodb.



import pymongo
from tkinter import *
from tkinter import ttk

class Input:

def __init__(self, root,):

self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")

self.mydb = self.myclient["mydatabase"]

self.mycol = self.mydb["input"]

title_label = Label(root, text="input")

title_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)

self.input_value = StringVar(root, value="")

self.input = ttk.Entry(root, textvariable=self.input_value)

self.input.grid(row=0, column=1, padx=10, pady=10, sticky=W)

self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())
self.submit_button.grid(row=1, column=0,
padx=10, pady=10, sticky=W)

def submit(self):
entry = "input": self.input_value
self.mycol.insert(entry)


root = Tk()

In = Input(root)

root.mainloop()


When trying to run this I get



bson.errors.InvalidDocument: Cannot encode object: <tkinter.StringVar object at 0x000001EC62343908>


I tried converting input_value to 'normal' string



self.input_value = str(StringVar(root, value=""))


By doing that I get the program to run but whatever I input into the entry field it writes 'PY_VAR0' to the database.



What am I doing wrong?







python mongodb tkinter pymongo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 14:21









Bryan Oakley

228k22302449




228k22302449










asked Mar 25 at 7:35









DracoTomesDracoTomes

112




112












  • Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

    – Neil Lunn
    Mar 25 at 7:45











  • Doing that still results in "PY_VAR0" being written to the database.

    – DracoTomes
    Mar 25 at 7:52






  • 1





    Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

    – Neil Lunn
    Mar 25 at 8:00

















  • Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

    – Neil Lunn
    Mar 25 at 7:45











  • Doing that still results in "PY_VAR0" being written to the database.

    – DracoTomes
    Mar 25 at 7:52






  • 1





    Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

    – Neil Lunn
    Mar 25 at 8:00
















Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

– Neil Lunn
Mar 25 at 7:45





Other way around. Rather than "assign a simple string" you need to coerce self.input_value to a "simple string", or at least a valid type for the BSON serializer. So "input": str(self.input_value)

– Neil Lunn
Mar 25 at 7:45













Doing that still results in "PY_VAR0" being written to the database.

– DracoTomes
Mar 25 at 7:52





Doing that still results in "PY_VAR0" being written to the database.

– DracoTomes
Mar 25 at 7:52




1




1





Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

– Neil Lunn
Mar 25 at 8:00





Get contents of a Tkinter Entry widget then? Possibly returns a dict from which you might need to further extract specific fields.

– Neil Lunn
Mar 25 at 8:00












1 Answer
1






active

oldest

votes


















1














Thanks Neil Lunn.



entry = "input": self.input_value.get()


is now working using the get method.



Another problem I found is that I wrote



self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit())


It actually needs to be



self.submit_button = ttk.Button(root,
text="Submit",
command=self.submit)


Without the parenthesis on self.submit.
Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333093%2fcannot-encode-object-tkinter-stringvar-object-pymongo%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Thanks Neil Lunn.



    entry = "input": self.input_value.get()


    is now working using the get method.



    Another problem I found is that I wrote



    self.submit_button = ttk.Button(root,
    text="Submit",
    command=self.submit())


    It actually needs to be



    self.submit_button = ttk.Button(root,
    text="Submit",
    command=self.submit)


    Without the parenthesis on self.submit.
    Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.






    share|improve this answer



























      1














      Thanks Neil Lunn.



      entry = "input": self.input_value.get()


      is now working using the get method.



      Another problem I found is that I wrote



      self.submit_button = ttk.Button(root,
      text="Submit",
      command=self.submit())


      It actually needs to be



      self.submit_button = ttk.Button(root,
      text="Submit",
      command=self.submit)


      Without the parenthesis on self.submit.
      Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.






      share|improve this answer

























        1












        1








        1







        Thanks Neil Lunn.



        entry = "input": self.input_value.get()


        is now working using the get method.



        Another problem I found is that I wrote



        self.submit_button = ttk.Button(root,
        text="Submit",
        command=self.submit())


        It actually needs to be



        self.submit_button = ttk.Button(root,
        text="Submit",
        command=self.submit)


        Without the parenthesis on self.submit.
        Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.






        share|improve this answer













        Thanks Neil Lunn.



        entry = "input": self.input_value.get()


        is now working using the get method.



        Another problem I found is that I wrote



        self.submit_button = ttk.Button(root,
        text="Submit",
        command=self.submit())


        It actually needs to be



        self.submit_button = ttk.Button(root,
        text="Submit",
        command=self.submit)


        Without the parenthesis on self.submit.
        Those caused the funktion to be executed at the start of the programm so it wrote empty strings even when using the get method.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 8:36









        DracoTomesDracoTomes

        112




        112





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333093%2fcannot-encode-object-tkinter-stringvar-object-pymongo%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현