Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
usando la variable de cadena con REGEXP, seleccione la consulta pymysql en python3

Tengo una aplicación web de chat bot django que toma la entrada del usuario e intenta encontrar la entrada coincidente en la base de datos y luego recupera la salida correspondiente.

Esta es una parte del código chatbot.py:

 # -*- coding: utf-8 -*- import re,string,sys import codecs import types import nltk import csv import pymysql from nltk import pos_tag from nltk.tokenize import regexp_tokenize from nltk.tokenize import word_tokenize from nltk.stem.isri import ISRIStemmer from chatbotx1.arabic_const import * from chatbotx1.normalize import * from chatbotx1.stemming import * from nltk.tag.stanford import StanfordPOSTagger from chatbotx1.ar_ghalat import * from chat.models import chat, user_info # initialize the connection to the female_database conn = pymysql.connect("***","***","***","***") cursor = conn.cursor() conn.text_factory = str def run_conversation_male(): last_B =' '.join(chat.objects.values_list('chatbot_response', flat=True).latest('id')) H = ' '.join(chat.objects.values_list('user_iput', flat=True).latest('id')) New_H= ' '.join(PreProcess_text(H)) cursor.execute('SELECT respoce FROM Male_Conversation_Engine WHERE request REGEXP?',[New_H]) reply = cursor.fetchone() if reply: B8=reply[0] new_data(H,B8) ID = chat.objects.values_list('id', flat=True).latest('id') chat.objects.filter(id=ID).update(chatbot_response=B8)

Antes estaba usando sqlite3, pero ahora, después de usar Mysql, recibí este mensaje de error:

 TypeError: not all arguments converted during string formatting

He probado esta solución:

 openconnect = pymysql.connect(host='xxxx',port=3306,user='xxx',passwd='xxx',db='xxxx',charset='utf8')

y recibí este mensaje de error:

 pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax;)

(PD: estoy usando Python3.5, Mysql, pymysql, Django10, y el texto está en idioma árabe)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El problema con la sintaxis es que cursor.execute no sabe dónde colocar New_H . Necesita %s para marcar el lugar de esa variable. Intenta cambiar tu SQL a este:

 SELECT respoce FROM Male_Conversation_Engine WHERE request REGEXP %s
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!