We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
jm-za
20 days agoExplorer | Level 3
Python SDK: DropboxTeam works in shell, but fails in Gunicorn service
Hello Dropbox Developer Community,
We're developing a Django application and are running into a very specific environment issue with the Python SDK when trying to access Team folders after an OAuth2 flow. We have code that works perfectly when run from a standalone script, but fails when executed within our Django/Gunicorn web application.
Our Goal:
Use an OAuth2 token from a team admin to create a client that can scan folders in the team's shared space.
The Problem:
Our application fails with the error: module 'dropbox.team' has no attribute 'DropboxTeam' when the web application tries to create a client.
However, when we run a simple test script from the server's command line, using the exact same logic and a manually generated token, it works perfectly. This proves the logic is correct, but the environment the Gunicorn service runs in is causing the issue.
Working Standalone Script & Output:
This script runs without errors from the command line:
# dropbox-test.py
import os
import time
from dotenv import load_dotenv
import dropbox
from dropbox import DropboxTeam
# Load environment variables from .env file
load_dotenv()
# Retrieve access token and admin member ID from environment
access_token = os.getenv("DROPBOX_ACCESS_TOKEN")
dbmid = os.getenv("DROPBOX_TEAM_ADMIN_MEMBER_ID")
# Initialize Dropbox Team client
dbx_team = DropboxTeam(access_token)
# Fetch and print team info — this works
team_info = dbx_team.team_get_info()
print("Team Name:", team_info.name)
# List team namespaces
namespaces = dbx_team.team_namespaces_list().namespaces
# Select target namespace
target_namespace = next(
ns for ns in namespaces if ns.name == "001 HAA Clients RETAINER"
)
# Create scoped client for the selected namespace — this works
dbx_target = dbx_team.as_user(dbmid).with_path_root(
dropbox.common.PathRoot.namespace_id(target_namespace.namespace_id)
)
print("Client for namespace created successfully.")
Output from shell:
Team info retrieved successfully. Team name: TEAM Client created successfully for target namespace
Failing Web Application Code:
This is the utility function in our Django app that fails. It is called by our views after the OAuth2 flow completes.
# from our docufy_app/dropbox_utils.py
import dropbox
import dropbox.team # This import fails under Gunicorn
from .models import DropboxCredential
def get_dbx_client():
credential = DropboxCredential.objects.first()
# ... token refresh logic ...
try:
# This line fails with the error, because for Gunicorn,
# dropbox.team has no attribute 'DropboxTeam'
team_client = dropbox.team.DropboxTeam(credential.access_token)
# ... rest of logic ...
except Exception as e:
# e is "AttributeError: module 'dropbox.team' has no attribute 'DropboxTeam'"
return None, f"An unexpected error occurred: {e}"
Our Environment:
Platform: Django / Gunicorn on a Linux server.
Python Version: Python 3.11.2
Dropbox SDK Version: Version: 12.0.2
Our Question:
We understand this is likely an environment issue, not a strict API one. Given that dropbox.team.DropboxTeam exists when we run a script from the command line but not when the same code is executed by our Gunicorn service, what could cause this discrepancy?
Could Gunicorn be picking up a different, older, system-wide installation of the dropbox library instead of the one in our project's virtual environment? Has anyone seen this behavior before and can suggest how to configure Gunicorn or the service file to ensure it uses the correct virtual environment and Python packages? Is this something to do with our Oath2 Flow that wasn't implemented correctly?
Thank you for any insight you can provide.
3 Replies
- Greg-DB20 days ago
Dropbox Community Moderator
The DropboxTeam class is defined as dropbox.dropbox_client.DropboxTeam, so you can access it from dropbox.dropbox_client; it's also available on just dropbox. (I see your dropbox-test.py and dropbox_utils.py examples actually do this differently from each other, which seems to explain the discrepancy; the former imports DropboxTeam from dropbox, but the latter references dropbox.team.DropboxTeam.)
It's not available as dropbox.team.DropboxTeam. Can you clarify if you saw that in some Dropbox sample code or documentation somewhere? If so, we'll be happy to see if we can get that fixed if possible. Thanks!
- jm-za20 days agoExplorer | Level 3
I’ve been coding this using Gemini 2.5 Pro. I don’t have any formal training in coding, so I’m dependent on the code I get from Gemini. Up until now, it’s been going really well—I’ve created several working projects like this. But in this case, something is off. Either Gemini has the wrong details, or it’s misinterpreting it, and it’s leading me down the wrong path.
The challenge now is that I’ve made so many changes that I’m not sure where I stand with this project anymore. I don’t know if you can guide me on how to go step-by-step through the process to test if OAuth2 is actually working correctly. And then, based on that, what should I be doing next?
I do have this project on Github and can go back to the version that was working with the normal token but will then have to go through the process again of implementing oath2 and the changes that goes with that.
Right now, I I’m going in circles, and I’m not sure how to get back on track.
- Greg-DB20 days ago
Dropbox Community Moderator
Thanks for the additional information. To be more specific, from your description here, you would need to change this line:
team_client = dropbox.team.DropboxTeam(credential.access_token)
by replacing "dropbox.team.DropboxTeam" with "dropbox.DropboxTeam". That would make the fixed line look like this:
team_client = dropbox.DropboxTeam(credential.access_token)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,037 PostsLatest Activity: 2 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!