简体   繁体   English

Django应用中的Python和gdata:“ POST方法不支持并发”

[英]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: 我正在使用以下软件:

  • Python 2.7.8 Python 2.7.8
  • Django 1.7.7 的Django 1.7.7
  • PyCharm 4.0.5 PyCharm 4.0.5
  • gdata 2.0.18 gdata 2.0.18
  • google-api-python-client 1.4.0 (not sure if relevant) google-api-python-client 1.4.0(不确定是否相关)
  • [many other packages that I'm not sure are relevant] [我不确定其他许多软件包是否相关]

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.

相关问题 django应用程序的多个实例,django是否支持此功能 - Multiple Instances of a django app, does django support this 使用Post方法python django的MultiValueDictKeyError - MultiValueDictKeyError with Post method python django heroku 不支持 django 应用程序并引发错误 - heroku does not support django app and raise the error Python Django Rest 框架:`.create()` 方法默认不支持可写嵌套字段 - Python Django Rest Framework: The `.create()` method does not support writable nested fields by default python中可以发布和获取的方法 - method in python that does post and get Intellij Ultimate 12是否支持Python / Django? - Does Intellij Ultimate 12 support Python/Django? Django / Python-串行线并发 - Django/Python - Serial line concurrency 我已经为我的应用获取了“授权代码”。 但是如何使用gdata-python-client将其发布到博客中? - I have got the “Authorization code” for my app. But how can I use it to post in the blogger using gdata-python-client? 为什么“发布”方法在我的 django 应用程序中不起作用? - Why the 'post' method is not working in my django app? Django:“请求”不包含“方法”(POST / GET) - Django: “request” does not contain the 'method' (POST/GET)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM