Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:51:29+00:00 2026-06-16T20:51:29+00:00

I’m trying use Google APIs Client Library for Python to rename drive file, here

  • 0

I’m trying use Google APIs Client Library for Python to rename drive file, here is the rename function:

def rename_file(service, file_id, new_title):
"""Rename a file.

Args:
    service: Drive API service instance.
    file_id: ID of the file to rename.
    new_title: New title for the file.
Returns:
    Updated file metadata if successful, None otherwise.
"""
try:
    file = {'title': new_title}
    # Rename the file.
    updated_file = service.files().patch(
            fileId=file_id,
            body=file,
            fields='title').execute()
    return updated_file
except errors.HttpError, error:
    logging.error('An error occurred: %s' % error)
    return None

But get errors, here is the trackback:

    Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/myproduct/libs/oauth2client/appengine.py", line 469, in check_oauth
    return method(request_handler, *args, **kwargs)
  File "/myproduct/main.py", line 31, in get
    new_title="file new name")
  File "/myproduct/gapi.py", line 148, in rename_file
    fields='title').execute()
  File "/myproduct/libs/oauth2client/util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/myproduct/libs/apiclient/http.py", line 676, in execute
    headers=self.headers)
  File "/myproduct/libs/oauth2client/util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/myproduct/libs/oauth2client/client.py", line 420, in new_request
    redirections, connection_type)
  File "/myproduct/libs/httplib2/__init__.py", line 1588, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/myproduct/libs/httplib2/__init__.py", line 1336, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/myproduct/libs/httplib2/__init__.py", line 1273, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/myproduct/libs/httplib2/__init__.py", line 1112, in request
    validate_certificate=self.validate_certificate)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/urlfetch.py", line 265, in fetch
    allow_truncated, follow_redirects, validate_certificate)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/urlfetch.py", line 286, in make_fetch_call
    raise InvalidMethodError('Invalid method %s.' % str(method))
InvalidMethodError: Invalid method PATCH.

So what should I do to use the rename_file function directly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:51:30+00:00Added an answer on June 16, 2026 at 8:51 pm

    As the error message indicates, PATCH is not yet supported by urlfetch, but an issue has been filed with the App Engine team and the issue is acknowledged.

    In the meantime, you can patch httplib2 to send an X-HTTP-METHOD-OVERRIDE header instead of using the PATCH method, as is indicated in a patch filed against httplib2.

    As that patch references some old code, I have provided the relevant snippet here:

    UNAUTHORIZED_METHODS = ['patch']
    HTTP_METHOD_OVERRIDE_HEADER = 'X-HTTP-Method-Override'
    HTTP_OVERRIDE_METHOD = 'POST'
    
    class AppEngineHttpConnection(httplib.HTTPConnection):
      ...
      def request(self, method, url, body=None, headers={}):
        if method.lower() in UNAUTHORIZED_METHODS:
          # No side-effects on provided headers.
          new_headers = {}
          new_headers.update(headers)
          new_headers[HTTP_METHOD_OVERRIDE_HEADER] = method
          method = HTTP_OVERRIDE_METHOD
          headers = new_headers
        super(AppEngineHttpConnection, self).request(method, url, body, headers)
    

    Since request is now simply the one defined in httplib.HTTPConnection, we can just re-use it while changing the one header we need.

    A similar override will be needed for the HTTPS version since it does not inherit from AppEngineHttpConnection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.