Python Forum
pymysql: insert query throws error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql: insert query throws error
#7
(Jan-24-2022, 02:14 PM)wardancer84 Wrote: what puzzles me all time time with this kind of stuff...how to get rid of all those square brakets in the output as this
looks not right.
No it does not look right. When I see [['aixacodbt']] I interpret it as a string in a list in a list. It needs unwrapping.
a = [['aixacodbt']]
b = a[0][0]
b
'aixacodbt'
print(b)
aixacodbt
You could unwrap these data before adding them to the tuple, but why are they wrapped in the first place? You should attack the problem at the source.
results = defaultdict(list)    # This designates the values to be lists
...
for key in sudo_obj.host_aliases:
        host_alias_list = []
        host_alias_list.append((key, sudo_obj.host_aliases[key]))  # host_alias_list is a list. Why double parentheses?? This would make a tuple of the contents of the list. Not useful in this stage.
        results['hostalias'].append(host_alias_list)   # Here you append the list to the list
You should add print statements to test what exactly happens in these steps. I have the impression it would be sufficient to do this:
for key in sudo_obj.host_aliases:
        results['hostalias'].append(sudo_obj.host_aliases[key])
I also tried to understand the sudoers object so I followed your link to python-sudoers but the examples all start with "from pysudoers import Sudoers" while you are doing: "from SudoersLib import *". I find no manuals on the usage of SudoersLib so I can't help with that.
Reply


Messages In This Thread
pymysql: insert query throws error - by wardancer84 - Jan-21-2022, 12:54 PM
RE: pymysql: insert query throws error - by ibreeden - Jan-24-2022, 06:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sqlite3 Conn Insert Value Error TylerDunbar 3 806 Sep-04-2023, 06:32 PM
Last Post: deanhystad
  pymysql; insert on duplicate key update fails wardancer84 4 2,105 Jun-28-2022, 08:14 PM
Last Post: Larz60+
  Mysql Syntax error in pymysql ilknurg 4 2,447 May-18-2022, 06:50 AM
Last Post: ibreeden
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,409 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Query Syntax Error hammer 2 1,662 Jan-03-2022, 02:30 PM
Last Post: hammer
  pymysql can't do SELECT * Pedroski55 3 3,044 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,216 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error using mariadb select query with form in python? shams 2 2,062 Jul-29-2021, 12:30 PM
Last Post: shams
  pyarrow throws oserror winerror 193 1 is not a valid win32 application aupres 2 3,855 Oct-21-2020, 01:04 AM
Last Post: aupres
  Function throws error but then works? Milfredo 10 3,909 Sep-12-2020, 05:16 AM
Last Post: Milfredo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020