res_json={ "id": 123456, "ip": "1.2.3.4" } res_str="vpc out limited" def return_val(): return res_str def create_vm(): try: response = return_val() return response['id'] #如果response是str 会报:TypeError: string indices must be integers, not str except TypeError as e: raise Exception(response) #CASE try: id=create_vm() print id except Exception as e: print "errinfo %s" %(e)