diff --git a/tensorflow/tools/docs/generate.py b/tensorflow/tools/docs/generate.py
index 73109d9dd85..8f2958d6a6a 100644
--- a/tensorflow/tools/docs/generate.py
+++ b/tensorflow/tools/docs/generate.py
@@ -22,6 +22,7 @@ import argparse
 import inspect
 import os
 
+import six
 import tensorflow as tf
 
 from tensorflow.tools.common import public_api
@@ -65,7 +66,7 @@ def write_docs(output_dir, base_dir, duplicate_of, duplicates, index, tree):
     raise
 
   # Parse and write Markdown pages, resolving cross-links (@{symbol}).
-  for full_name, py_object in index.iteritems():
+  for full_name, py_object in six.iteritems(index):
 
     if full_name in duplicate_of:
       print('Not writing docs for %s, duplicate of %s.' % (
diff --git a/tensorflow/tools/docs/parser.py b/tensorflow/tools/docs/parser.py
index f4451a6e258..4e3442f92f0 100644
--- a/tensorflow/tools/docs/parser.py
+++ b/tensorflow/tools/docs/parser.py
@@ -23,6 +23,7 @@ import inspect
 import os
 import re
 
+import six
 
 # A regular expression capturing a python indentifier.
 IDENTIFIER_RE = '[a-zA-Z_][a-zA-Z0-9_]*'
@@ -616,7 +617,7 @@ def generate_global_index(library_name, root_name, index, duplicate_of):
     A string containing an index page as Markdown.
   """
   symbol_links = []
-  for full_name, py_object in index.iteritems():
+  for full_name, py_object in six.iteritems(index):
     index_name = full_name or root_name
     if (inspect.ismodule(py_object) or inspect.isfunction(py_object) or
         inspect.isclass(py_object)):