[英]Python & gdata within Django app: “POST method does not support concurrency”
I am trying to use gdata within a Django app to create a directory in my google drive account. 我正在尝试在Django应用程序中使用gdata在我的Google驱动器帐户中创建目录。 This is the code written within my Django view: 这是在我的Django视图中编写的代码:
def root(request):
from req_info import email, password
from gdata.docs.service import DocsService
print "Creating folder........"
folder_name = '2015-Q1'
service_client = DocsService(source='spreadsheet create')
service_client.ClientLogin(email, password)
folder = service_client.CreateFolder(folder_name)
Authentication occurs without issue, but that last line of code triggers the following error: 进行身份验证没有问题,但是最后一行代码触发以下错误:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.7
Exception Type: RequestError
Exception Value: {'status': 501, 'body': 'POST method does not support concurrency', 'reason': 'Not Implemented'}
I am using the following software: 我正在使用以下软件:
What's frustrating is that the exact same code (see below) functions perfectly when I run it in its own, standalone file (not within a Django view). 令人沮丧的是,当我在自己的独立文件(不在Django视图中)中运行完全相同的代码(见下文)时,它们的功能完美。
from req_info import email, password
from gdata.docs.service import DocsService
print "Creating folder........"
folder_name = '2015-Q1'
service_client = DocsService(source='spreadsheet create')
service_client.ClientLogin(email, password)
folder = service_client.CreateFolder(folder_name)
I run this working code in the same virtual environment and the same PyCharm project as the code that produced the error. 我在与产生错误的代码相同的虚拟环境和相同的PyCharm项目中运行此工作代码。 I have tried putting the code within a function in a separate file, and then having the Django view call that function, but the error persists. 我尝试将代码放在一个函数中的单独文件中,然后让Django视图调用该函数,但错误仍然存在。
I would like to get this code working within my Django app. 我想让此代码在我的Django应用程序中正常工作。
I don't recall if I got this to work within a Django view, but because Google has since required the use of Oauth 2.0, I had to rework this code anyways. 我不记得我是否可以在Django视图中使用它,但是由于Google自此以来要求使用Oauth 2.0,因此无论如何我都不得不重新编写代码。 I think the error had something to do with my simultaneous use of two different packages/clients to access Google Drive. 我认为该错误与我同时使用两个不同的程序包/客户端访问Google云端硬盘有关。
Here is how I ended up creating the folder using the google-api-python-client package: 这是我最终使用google-api-python-client包创建文件夹的方式:
from google_api import get_drive_service_obj, get_file_key_if_exists, insert_folder
def create_ss():
drive_client, credentials = get_drive_service_obj()
# creating folder if it does not exist
folder = get_file_key_if_exists(drive_client, 'foldername')
if folder: # if folder exists
print 'Folder "' + folder_name + '" already exists.'
else: # if folder doesn't exist
print 'Creating folder........"' + folder_name + '".'
folder = insert_folder(drive_client, folder_name)
After this code, I used a forked version (currently beta) of sheetsync to copy my template spreadsheet and populate the new file with my data. 在这段代码之后,我使用了一个分页的sheetsync版本(当前为beta)来复制模板电子表格,并使用我的数据填充新文件。 I then had to import sheetsync after the code above to avoid the "concurrency" error. 然后,我不得不在上面的代码后导入sheetsync,以避免“并发”错误。 (I could post the code involving sheetsync here too if folks want, but for now, I don't want to get too far off topic.) (如果人们愿意,我也可以在此处发布涉及sheetsync的代码,但就目前而言,我不想太离题。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.