bmarc4321
bmarc4321

Reputation: 13

Traceback (most recent call last) error after creating database with python/ArangoDB

So I've created a database called "school" which appears in the ArangoDB web UI. However after running my app.py file I receive the following trace error in the command prompt which prevents the python server from booting up.

Note: I'm running Python 3.7.3 and Flask 1.0.2 with the python driver pyArango-1.3.2 to connect to ArangoDB version 3.4.6-1

Here's the rather simple code I'm using...

from flask import Flask, session, render_template, redirect, flash, url_for, send_from_directory, request
from flask_cors import CORS
from werkzeug.utils import secure_filename
from pyArango.connection import *

conn = Connection(username="root", password="password")

conn.createDatabase(name="school")

db = conn["school"]

Any idea what might be causing the error below?:

  File "C:\Users\username\newproject_v2\newprojectv2\app.py", line 9, in <module>
    conn.createDatabase(name="school")
  File "C:\Users\username\Envs\newprojectv2\lib\site-packages\pyArango\connection.py", line 163, in createDatabase
    raise CreationError(data["errorMessage"], r.content)
pyArango.theExceptions.CreationError: duplicate name. Errors: b'{"error":true,"errorMessage":"duplicate name","code":409,"errorNum":1207}'

Upvotes: 1

Views: 372

Answers (1)

Madhan Varadhodiyil
Madhan Varadhodiyil

Reputation: 2116

I think you can create a database only once. Check if the connection already has a db with the same name. If it doesn't exists then create one. hasDatabase can help you there.

from flask import Flask, session, render_template, redirect, flash, url_for, send_from_directory, request
from flask_cors import CORS
from werkzeug.utils import secure_filename
from pyArango.connection import *

conn = Connection(username="root", password="password")
if not conn.hasDatabase("school"):
    conn.createDatabase(name="school")

db = conn["school"]

Upvotes: 1

Related Questions