Category : mysql-connector-python

I have the following script to do some calculations with stored data in a mysql database: class summer: like_points=0 reply_points=0 total_rts=0 rt_points=0 total=0 def sum_fun(): try: con = mysql.connector.connect(host=’localhost’, database=’twitterdb’, user=’root’, password=’mypasword’, charset=’utf8′) if con.is_connected(): cursor = con.cursor(buffered=True) def sum_rts(): cursor.execute("SELECT SUM(retweet_count) FROM twitterdb.Metrics") sum1=cursor.fetchall()[0][0] return int(sum1) def sum_replies(): cursor.execute("SELECT SUM(reply_count) FROM twitterdb.Metrics") sum2=cursor.fetchall()[0][0] return ..

Read more

Long code ahead, kindly help out. I am trying to create a point system for tweets. I have streamed tweets with #Python to a MySQL database and I am trying to create a points system for the same. from typing_extensions import Self import requests import os import json import mysql.connector from mysql.connector import Error bearer_token ..

Read more

I have this code log_in = f’SELECT user_name,fname FROM users;’ cursor = connection.cursor() cursor.execute(log_in) result = cursor.fetchall() cursor.close() print(type(result)) print(result) print(‘bfuqua’ in result) if ‘bfuqua’ in result: unique = False print(‘That user name already exists. Please try again.’) And when I print the type I get <class ‘list’> as the return type, [(‘bfuqua’,)] as the ..

Read more

I’m using the mysql-connector-python library to connect and write to a MySQL 5.7 db. I’ve set the encoding to utf8mb4 with cursor.execute(‘SET CHARACTERS SET utf8mb4’), and even included it in my connect settings: import mysql.connector from mysql.connector import Error sg_titles_db_settings = { ‘user’: <user>, ‘password’: <password>, ‘host’: <host>, ‘port’: <port>, ‘database’: <db>, ‘charset’: ‘utf8’ } ..

Read more

I’m trying to update my MySQL database using mysql.connector. I’m getting the following error and I’m not sure if it is due to syntax or not. This is because the column in question does exist within the database: ProgrammingError: 1054 (42S22): Unknown column ‘pallet_quantity’ in ‘field list’ Here is the other relevant information for reproducibility: ..

Read more

I have a python file with MySQL setup like below. import mysql.connector.pooling import logging from utils.helper_funcs import create_log, get_retry_count, get_default_sleep_time import time class DBConnection(): """create a mysql connection pool""" pool = None connection = None cusror = None def create_pool(self, pool_name="testpool"): self.pool = mysql.connector.pooling.MySQLConnectionPool( pool_name=pool_name, pool_reset_session=True, **self.dbconfig) def open_thread(self): """Open connection """ if (self.pool is ..

Read more

Views.py file from django.shortcuts import render from django.views.generic import ListView,DetailView,CreateView,UpdateView,DeleteView from .models import News_Post,Category from .forms import addArticleForm,updateArticleForm from django.template import loader from django.urls import reverse_lazy import mysql.connector # Create your views here. mydb = mysql.connector.connect( host="localhost", user="root", password="goodboy123", database = "nexus360" ) cursor = mydb.cursor() # — Display all the news on the homePage ..

Read more