title: Spark Sql: TypeError("StructType can not accept object in type %s" % type(obj))
body: <p>I am currently pulling data from SQL Server using PyODBC and trying to insert into a table in Hive in a Near Real Time (NRT) manner. </p>
  
  <p>I got a single row from source and converted into List[Strings] and creating schema programatically but while creating a DataFrame, Spark is throwing StructType error.</p>
  
  <pre><code>&gt;&gt;&gt; cnxn = pyodbc.connect(con_string)
  &gt;&gt;&gt; aj = cnxn.cursor()
  &gt;&gt;&gt;
  &gt;&gt;&gt; aj.execute("select * from tjob")
  &lt;pyodbc.Cursor object at 0x257b2d0&gt;
  
  &gt;&gt;&gt; row = aj.fetchone()
  
  &gt;&gt;&gt; row
  (1127, u'', u'8196660', u'', u'', 0, u'', u'', None, 35, None, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, u'', 0, None, None)
  &gt;&gt;&gt; rowstr = map(str,row)
  &gt;&gt;&gt; rowstr
  ['1127', '', '8196660', '', '', '0', '', '', 'None', '35', 'None', '0', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', '', '0', 'None', 'None']
  
  &gt;&gt;&gt; schemaString = " ".join([row.column_name for row in aj.columns(table='tjob')])
  
  &gt;&gt;&gt; schemaString
  u'ID ExternalID Name Description Notes Type Lot SubLot ParentJobID ProductID PlannedStartDateTime PlannedDurationSeconds Capture01 Capture02 Capture03 Capture04 Capture05 Capture06 Capture07 Capture08 Capture09 Capture10 Capture11 Capture12 Capture13 Capture14 Capture15 Capture16 Capture17 Capture18 Capture19 Capture20 User UserState ModifiedDateTime UploadedDateTime'
  
  &gt;&gt;&gt; fields = [StructField(field_name, StringType(), True) for field_name in schemaString.split()]
  &gt;&gt;&gt; schema = StructType(fields)
  
  &gt;&gt;&gt; [f.dataType for f in schema.fields]
  [StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType, StringType]
  
  &gt;&gt;&gt; myrdd = sc.parallelize(rowstr)
  
  &gt;&gt;&gt; myrdd.collect()
  ['1127', '', '8196660', '', '', '0', '', '', 'None', '35', 'None', '0', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', '', '0', 'None', 'None']
  
  &gt;&gt;&gt; schemaPeople = sqlContext.createDataFrame(myrdd, schema)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/apps/opt/cloudera/parcels/CDH-5.5.2-1.cdh5.5.2.p0.4/lib/spark/python/pyspark/sql/context.py", line 404, in createDataFrame
      rdd, schema = self._createFromRDD(data, schema, samplingRatio)
    File "/apps/opt/cloudera/parcels/CDH-5.5.2-1.cdh5.5.2.p0.4/lib/spark/python/pyspark/sql/context.py", line 298, in _createFromRDD
      _verify_type(row, schema)
    File "/apps/opt/cloudera/parcels/CDH-5.5.2-1.cdh5.5.2.p0.4/lib/spark/python/pyspark/sql/types.py", line 1132, in _verify_type
      raise TypeError("StructType can not accept object in type %s" % type(obj))
  TypeError: StructType can not accept object in type &lt;type 'str'&gt;
  </code></pre>