python search in a string with find
Question: i'm trying to find a string in the headers of response after login in
wordpress script , so i tried with this find method :

    
    
    import urllib, urllib2, os, sys, requests , re
    ....
    ....
    req = urllib2.Request(url, urllib.urlencode(dict(data)), dict(headers))
    response = urllib2.urlopen(req)
    res = dict(response.headers)
    res1 = 'wp-admin'
    print res.find(res1);
    

and i get this error :

    
    
    Traceback (most recent call last):
      File "C:\Python27\wp2\wp12.py", line 29, in <module>
        print res.find(res1);
    AttributeError: 'dict' object has no attribute 'find'
    

so any idea how to search in dict(response.headers) or transform it into text
to use find function correctly ? and thanks a lot for any help :)


Answer: You cannot use "find" on dict, but you can find in keys/values. Followed code
will find wp-admin in values and return key/value in dict. add k.find if you
also want find in keys.

    
    
    dict([(k,v) for k,v in res.iteritems() if v.find('wp-admin') >=0])
    

