title: Why won't this string convert to dict?
body: <p>I have a small flask app that I'm using to import jobs from a database. The route I use for importing the jobs is as follows (job_details is a submit button in a form for each individual job that passes the job):</p>
  <pre><code>@app.route(&quot;/job-import&quot;, methods=[&quot;POST&quot;])
  def job_import():
      if &quot;loggedin&quot; in session:
          if request.method == 'POST':
              job = request.form['job_details']
  
              # Job comes in string format, therefore needs to be converted to DICT
                  job = ast.literal_eval(job)
  ...
  </code></pre>
  <p>I want to convert the string I get from <code>request.form['job_details']</code> to a dict so I can then parse it and access the values via <code>job['description'], job['title']</code> etc. However, I keep getting a 'TypeError: string indices must be integers' error. I am sure it is being passed as a string, and as far as I can find <code>ast.literal_eval()</code> should convert the string to a dict, however this is clearly not the case. Why is this?</p>
  <p>Some sample input for a job from my app:</p>
  <p><code>&quot;{'id': 3, 'date': datetime.date(2022, 2, 3), 'job_title': 'Cool title', 'contact_name': 'Mr Cool', 'contact_email': 'coolio@coolcom.cool', 'location': 'Coolville', 'expiry_date': datetime.date(2022, 5, 1), 'salary': None, 'twitter': None, 'listing_type': None, 'description': 'a cool job for cool people to do cool things', 'url': 'cooljobs.cool', 'logo': None, 'status': None}&quot;</code></p>
  <p>Full traceback:</p>
  <p>return self.wsgi_app(environ, start_response)
  File &quot;&quot;, line 2450, in wsgi_app response = self.handle_exception(e)
  File &quot;&quot;, line 1867, in handle_exception reraise(exc_type, exc_value, tb) File &quot;&quot;, line 39, in reraise raise value
  File &quot;&quot;, line 2447, in wsgi_app response = self.full_dispatch_request()
  File &quot;&quot;, line 1952, in full_dispatch_request rv = self.handle_user_exception(e)
  File &quot;&quot;, line 1821, in handle_user_exception reraise(exc_type, exc_value, tb)
  File &quot;&quot;, line 39, in reraise raise value
  File &quot;&quot;, line 1950, in full_dispatch_request rv = self.dispatch_request() File &quot;&quot;, line 1936, in dispatch_request return self.view_functionsrule.endpoint
  File &quot;&quot;, line 57, in app if job['listing_type'] == &quot;Basic job listing (free)&quot;:</p>