import os.path
import webbrowser
import pydrive.auth, pydrive.drive

def upload(document):
    """Upload .docx file to Google Drive and return a web view link to it."""

    auth = pydrive.auth.GoogleAuth()
    auth.LocalWebserverAuth()

    gdrive = pydrive.drive.GoogleDrive(auth)

    gdoc = gdrive.CreateFile({
        "title": os.path.splitext(os.path.basename(document))[0]
    })
    gdoc.SetContentFile(document)
    gdoc.Upload({"convert": True})

    webbrowser.open(gdoc["alternateLink"])

    return gdoc["alternateLink"]

import os.path
import webbrowser
import pydrive.auth, pydrive.drive

def upload(document):
    """Upload .docx file to Google Drive and return a web view link to it."""

    auth = pydrive.auth.GoogleAuth()
    auth.CommandLineAuth()

    gdrive = pydrive.drive.GoogleDrive(auth)

    gdoc = gdrive.CreateFile({
        "title": os.path.splitext(os.path.basename(document))[0]
    })
    gdoc.SetContentFile(document)
    gdoc.Upload({"convert": True})

    webbrowser.open(gdoc["alternateLink"])

    return gdoc["alternateLink"]

Switch from local server to command line auth to fix upload in Docker.
GDrive: Switch from local server to command line auth to fix upload in Docker.

  import os.path
  import webbrowser
  import pydrive.auth, pydrive.drive
  
  def upload(document):
      """Upload .docx file to Google Drive and return a web view link to it."""
  
      auth = pydrive.auth.GoogleAuth()
-     auth.LocalWebserverAuth()
+     auth.CommandLineAuth()
  
      gdrive = pydrive.drive.GoogleDrive(auth)
  
      gdoc = gdrive.CreateFile({
          "title": os.path.splitext(os.path.basename(document))[0]
      })
      gdoc.SetContentFile(document)
      gdoc.Upload({"convert": True})
  
      webbrowser.open(gdoc["alternateLink"])
  
      return gdoc["alternateLink"]
  
Switch from local server to command line auth to fix upload in Docker.
## Code Before:
import os.path
import webbrowser
import pydrive.auth, pydrive.drive

def upload(document):
    """Upload .docx file to Google Drive and return a web view link to it."""

    auth = pydrive.auth.GoogleAuth()
    auth.LocalWebserverAuth()

    gdrive = pydrive.drive.GoogleDrive(auth)

    gdoc = gdrive.CreateFile({
        "title": os.path.splitext(os.path.basename(document))[0]
    })
    gdoc.SetContentFile(document)
    gdoc.Upload({"convert": True})

    webbrowser.open(gdoc["alternateLink"])

    return gdoc["alternateLink"]

## Instruction:
Switch from local server to command line auth to fix upload in Docker.
## Code After:
import os.path
import webbrowser
import pydrive.auth, pydrive.drive

def upload(document):
    """Upload .docx file to Google Drive and return a web view link to it."""

    auth = pydrive.auth.GoogleAuth()
    auth.CommandLineAuth()

    gdrive = pydrive.drive.GoogleDrive(auth)

    gdoc = gdrive.CreateFile({
        "title": os.path.splitext(os.path.basename(document))[0]
    })
    gdoc.SetContentFile(document)
    gdoc.Upload({"convert": True})

    webbrowser.open(gdoc["alternateLink"])

    return gdoc["alternateLink"]
