title: Python C API: Dictionary not parsing properly
body: <p>I am executing a python function from C. The function returns a dictionary, which I was hoping to map to a C++ map.</p>
  
  <p>When I call PyObject_Str, I get a perfect string representation of the dictionary. However, PyDict_Check says it's not a dictionary:</p>
  
  <pre><code>        // Call the function
      PyObject* args = PyTuple_Pack(1,PyString_FromString((const char *) blob_pointer)); // argument is irrelevant for the question
      PyObject *dict = PyObject_CallObject(serialize_func, args);
      Py_DecRef(args);
  
      // THIS PRINTS A DICT!?!
      std::cout &lt;&lt; PyString_AsString(PyObject_Str(dict)) &lt;&lt; std::endl;
  
      //Nope
      if (dict == NULL) {
          std::cout &lt;&lt; "Return value was null!" &lt;&lt; std::endl;
          PyErr_Print();
      }
  
      std::cout &lt;&lt; "Called python function" &lt;&lt; std::endl;
  
      // Returns false!
      if (!PyDict_Check(dict)) {
          PyErr_Print();
          std::cout &lt;&lt; "serialized value was not a dict" &lt;&lt; std::endl;
          Py_DecRef(dict);
          return true;
      }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{...} // The expected dictionary
  Called python function
  serialized value was not a dict
  Done.
  </code></pre>
  
  <p>Why is this happening? Is it a bug in the Python C API or am I missing something?</p>
  
  <p>The python version is 2.7.13.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I ended up using an ugly workaround of getting the string representation and building a c++ map from it. I would still like to know why the code behaved the way it did though.</p>