Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Python and MariaDB question

    Hi, I have the following function defined in a python script, it is the only function defined in the script:

    Code:
    def sendNotify(url):
        headers = {"TTL": "1800"}
        response = requests.post(url, headers=headers)
        print(response.status_code)
        if response.status_code == 410:
            try:
                cursor.execute('DELETE FROM endpoints WHERE endpoint = %s', (url,))
            except mariadb.Error as error:
                print("Error: {}".format(error))
            print(url)
    The SQL query isn't working. Elsewhere I have defined cursor as such:

    Code:
    try:
        dbase = mariadb.connect(user='userd', password='somepass', database='some_database')
        
    except:
        sys.exit(1)
        
    cursor = dbase.cursor()
    The cursor works as it is able query stuff when not in a python def block and I was under the impression that stuff not in a def block are global in scope, so it should work but it doesn't seem to and I can't even get the error.

    From the print(url) I can see that the HTTP 410 status code is being triggered, and that what is being printed matches the endpoint field in the database - but the database entry isn't deleted like it should be. I don't see an exception either.

    Any Python gurus know what I am missing?
    Last edited by VIPStephan; 12-16-2016 at 08:52 AM. Reason: added “resolved” mark

  2. #2
    New to the CF scene
    Join Date
    Nov 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh I just found it - I needed to execute a dbase.commit()

  3. #3
    New Coder
    Join Date
    Nov 2016
    Location
    South Africa, Cape Town
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    Close thread?

  4. #4
    Administrator VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    10,729
    Thanks
    6
    Thanked 1,277 Times in 1,247 Posts
    Only a moderator can close threads. Users can set them to “resolved”, though, by editing the first post and setting the title to “resolved”.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •