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 8295347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:33:19+00:00 2026-06-08T14:33:19+00:00

I have a url which I want to save into the MySQL database using

  • 0

I have a url which I want to save into the MySQL database using the "cursor" tool offered by django, but I keep getting the "not enough arguments for format string" error because this url contains some escaped characters (non-ascii characters). The testing code is fairly short:

test.py

import os 
import runconfig #configuration file 
os.environ['DJANGO_SETTINGS_MODULE'] = runconfig.django_settings_module 
from django.db import connection,transaction 
c = connection.cursor() 
url = "http://www.academicjournals.org/ijps/PDF/pdf2011/18mar/G%C3%B3mez-Berb%C3%ADs et al.pdf"

dbquery = "INSERT INTO main_crawl_document SET url="+url 
c.execute(dbquery) 
transaction.commit_unless_managed()

The full error message is

Traceback (most recent call last):
  File "./test.py", line 14, in <module>
    c.execute(dbquery)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/util.py", line 38, in execute
    sql = self.db.ops.last_executed_query(self.cursor, sql, params)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/__init__.py", line 505, in last_executed_query
    return smart_unicode(sql) % u_params
TypeError: not enough arguments for format string

Can anybody help me?

  • 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-08T14:33:20+00:00Added an answer on June 8, 2026 at 2:33 pm

    You’re opening yourself up for a possible SQL injection. Instead, use c.execute() properly:

    url = "http://www.academicjournals.org/ijps/PDF/pdf2011/18mar/G%C3%B3mez-Berb%C3%ADs et al.pdf"
    dbquery = "INSERT INTO main_crawl_document SET url=?" 
    c.execute(dbquery, (url,)) 
    transaction.commit_unless_managed()
    

    The .execute method should accept an iterable of parameters to use for escaping, assuming it’s the normal dbapi method (which it should be with Django).

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

Sidebar

Related Questions

Hi have this URL string which I need to extract possibly using regex but
I want to make customer route for url which have parameters. <a href='javascript:void(0)' onclick=window.location='<?php
I have an App in which i have an URL, I dont want to
I have a problem with textarea content which I want to save it in
I have a flash file which calls a url like: http://test.com/savethis/123456/ I just want
I have a view which I want to have 3 buttons; Save, Save &
I have a URL which can be any of the following formats: http://example.com https://example.com
I have a url which could be www.website.com/order/?pg3=2 or www.website.com/orderstatus/?pg2= There could be several
I have a url which have a response in Json lon=-0.1275&pg=0 I parsed the
I have a url which has some get variables in it like: domain.com/recover?email=my@email.com&token=abc123 inside

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.