不以正确的格式从python脚本返回代码

时间:2014-12-11 16:43:14

标签: php python json

当我使用这个PHP代码时(我对php来说相当新!)

<?php 

if (isset($_GET["name"]))
{
$output = system("python /usr/custom/player.py ".escapeshellarg($_GET["name"]));
echo $output;
}

?>

(/usr/custom/player.py的代码是:

#!/usr/bin/env python

import pypixel, json, sys

name = sys.argv[1]
api = pypixel.HypixelAPI("private")
printable = json.dumps(api.userByName(name), indent=4, separators=(',', ': '))
for i in printable.split("\n"):
    print(i)

(Pypixel是一个自定义库,但它确实有效)

它应该打印出json.dumps格式,如python代码中所述,但它不会

(当我进入网站时,输入http://example.com/player.php?name=destruc7i0n并运行它,我得到的回复不是json.dumps格式。

{ "player": { "mostRecentGameType": "QUAKECRAFT", "fireworkStorage": [ { "fade_colors": "255,255,255:102,76,51", "twinkle": true, "selected": false, "shape": "BURST", "trail": true, "colors": "76,127,153", "flight_duration": 1 }, { "fade_colors": "25,25,25:153,51,51", "twinkle": true, "selected": true, "shape": "STAR", "trail": true, "colors": "153,153,153:102,76,51:76,127,153", "flight_duration": 1 }, { "fade_colors": "127,63,178", "twinkle": true, "selected": false, "shape": "CREEPER", "trail": true, "colors": "127,204,25:102,127,51", "flight_duration": 1 } ], "newPackageRank": "MVP", "packageRank": "VIP_PLUS", "timePlaying": 2979, "skin": { "signature": "XCDDTT4qgMRn081H5Jw1PeSKjFLA5RzZEwlCOq6jKy9S7tf67LHIBzOMB95HKFOQ8ObOdd/UhFf/u5Cn9t5Ck6Nh9AQZ70MWDkwA0jB70Bj+D7dG+46xfjbYfbIppi01gCva9/Y6z+a3m2R4/jqT4a+LUQj6j4PXeblB2oCd5MIWMplg5krFpBmwSnyLUTAujrfVddLKTAg2+T+kCRIn5/6myR1O0h1F6rwhF0tU8X9L6NWP0+RMH5ebodBDE/1YVOsnjEPnatqqTj1AaMFCrfcZfFaWE62ebWgU7qPrgfFyysPHXoTI1AROop7Ml2Ht4CE6MU6MG6CfdJ9wUmpbXR17rEjSTRL/GjCPtznDuVV2OTvZRbDqBic2R+SNJPLqCY7ePeFlh45RF8ZeXr8TdPVSCwttwDSPFz6szOiwcNRqeuPEuSfZ+VYg4LoolfP9IK4x/o5YCNF+jaZSCI60H++Uekc51zisM6jybYOc5FlVHMZTD8jjn4XfAO/m6Z7Dfd7T6VTRP73UC5VzC4XZxfswowbGqcZRVFGh/7Pk4wXFto3373jsxQoCF/jL4kWlvvDTPMQAiXDtBc6Ah0IkpYzMCfhtIscx8CYm0wZSQFPXaW/omtivdG2ypwTb4sx1j1wiMEUkc/o2sIl+2QRJrdTPcPb1ZBLJ9OHFSAThX4M=", "value": "eyJ0aW1lc3RhbXAiOjE0MTUzMDc4MTc1NDYsInByb2ZpbGVJZCI6IjJkOGNmODQ0ZmEzNDQxYzM4ZDRlNTk3YjMyNjk3OTA5IiwicHJvZmlsZU5hbWUiOiJkZXN0cnVjN2kwbiIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9hOGIxMWY0OTc5ZDc5ZjYyY2YzOTI0YTk4MThhNjZjNWY2ZTgxZmVhZDljZGFkNWFiZWFmOTdjNzVmNWM0In19fQ==", "timeoutStart": 1415307894445 }, "auto_spawn_pet": true, "wardrobe": "IRON_CHESTPLATE,CHAINMAIL_LEGGINGS,IRON_BOOTS,CHAINMAIL_HELMET", "mostRecentlyThanked": "Quitseeker90736", "friendRequests": [], "mostRecentlyTipped": "lupare", "stats": { "Arena": { "rating": 934.1702221926568, "healed_4v4": 600, "games_2v2": 14, "healed_2v2": 13600, "damage_4v4": 8767, "coins": 9027, "offensive": "lightning_strike", "wins_2v2": 3, "win_streaks_2v2": 1, "games_4v4": 5, "losses_2v2": 12, "damage_2v2": 45361, "deaths_2v2": 11, "kills_2v2": 4, "losses_4v4": 3, "wins_4v4": 2, "packages": [ "lightning_strike" ], "deaths_4v4": 4, "win_streaks_4v4": 2 }, "Arcade": { "kills_dayone": 19, "deaths_throw_out": 4, "melee_weapon": "COMBAT_KNIFE", "deaths_oneinthequiver": 2, "kills_dragonwars2": 0, "kills_oneinthequiver": 2, "coins": 7325, "kills_throw_out": 8, "max_wave": 26, "bounty_kills_oneinthequiver": 0, "blood": false, "stamp_level": 1, "poop_collected": 7, "time_stamp": 1416609385063, "headshots_dayone": 6, "packages": [ "combat_knife_melee" ], "wins_farm_hunt": 1 }, "HungerGames": { "slimeyslime": 1, "tim": 1, "coins": 3721, "monthly_kills_b": 6, "kills": 159, "deaths": 257, "reddragon": 1, "necromancer": 2, "chosen_taunt": "RICH_JAMES", "creepertamer": 1, "speleologist": 4, "arachnologist": 1, "rogue": 2, "astronaut": 1, "aura": "SLIME_PARTICLE", "wins": 4, "horsetamer": 1, "chosen_victorydance": "DRAGON_RIDER", "packages": [ "default_taunt", "package_taunt" ], "wolftamer": 1, "blaze": 3 }, "MCGO": { "selectedCarbineDev": "G36C", "deaths": 70, "kills_10_2014": 114, "bombs_planted": 9, "killsNew_11_2014": 39, "round_wins": 136, "packages": [ "taunt_rekt", "g36c", "taunt_tooeasy" ], "game_wins": 23, "coins": 633, "pocket_change": 1, "carbine_damage_increase": 2, "killsNew": 77, "killsNew_5_10_2014": 24, "kills_4_10_2014": 25, "cop_kills": 77, "kills": 164, "shots_fired": 3765, "criminal_kills": 87, "killsNew_4_10_2014": 14, "killsNew_2_11_2014": 39, "kills_3_10_2014": 65, "carbine_recoil_reduction": 2, "carbine_cost_reduction": 3, "bounty_hunter": 2, "body_armor_cost": 2, "kills_2_11_2014": 39, "kills_11_2014": 39, "carbine_reload_speed_reduction": 2, "pistol_damage_increase": 1, "headshot_kills": 138, "pistol_recoil_reduction": 1, "killsNew_10_2014": 38, "pistol_reload_speed_reduction": 1, "kills_5_10_2014": 24 }, "VampireZ": { "vampire_deaths": 32, "coins": 9850, "vampire_kills": 7, "human_kills": 7, "human_deaths": 11 }, "Walls": { "coins": 8950, "kills": 15, "deaths": 88, "wins": 21, "losses": 13, "packages": [ "sage" ] }, "Walls3": { "finalKills": 15, "finalDeaths": 12, "deaths": 125, "weeklyKills_Herobrine": 14, "weeklyDeaths_Herobrine": 17, "losses_Herobrine": 42, "finalKills_Herobrine": 15, "weeklyKills": 18, "losses_Enderman": 1, "weeklyKills_Spider": 4, "weeklyLosses_Herobrine": 3, "coins": 7278, "mutations_visibility": false, "weeklyWins": 2, "weeklyWins_Herobrine": 1, "herobrine_d": 5, "herobrine_g": 4, "herobrine_a": 5, "herobrine_b": 2, "herobrine_c": 2, "kills_Herobrine": 158, "kills_Spider": 4, "kills": 162, "weeklyWins_Spider": 1, "chosen_class": "Herobrine", "spider_c": 2, "spider_a": 2, "blood": false, "spider_d": 3, "wins_Spider": 1, "wins_Herobrine": 13, "packages": [ "herobrine_skill_alternate_active" ], "weeklyLosses_Spider": 1, "losses_Spider": 1, "weeklyDeaths_Spider": 11, "weeklyDeaths": 28, "spider_b": 2, "losses_Zombie": 1, "weeklyLosses": 4, "wins": 14, "deaths_Herobrine": 111, "losses": 46, "war_cry": "CYCLONE", "deaths_Spider": 11, "spider_g": 2 }, "Paintball": { "superluck": 4, "fortune": 3, "godfather": 0, "kills": 1087, "deaths": 1200, "shots_fired": 20479, "coins": 2885, "wins": 43, "killstreaks": 4, "packages": [ "tntrain", "vip_agentk_hat", "normal_hat", "tripleshot", "nuke", "plusten", "superstrongarm" ], "hat": "vip_agentk_hat" }, "Quake": { "case": "STONE_HOE", "muzzle": "NONE", "kills": 2167, "deaths": 2669, "wins": 8, "coins": 3618, "monthly_kills_b": 118, "trigger": "ONE_POINT_TWO", "sight": "YELLOW", "barrel": "SMALL_BALL", "packages": [ "cold_war", "compass", "trigger.one_point_four", "case.stone_hoe", "controlfreakhat", "sight.yellow", "barrel.small_ball", "instant_respawn", "trigger.one_point_two", "muzzle.none" ], "hat": "controlfreakhat", "killstreaks": 20 }, "TNTGames": { "wins_capture": 78, "witherwizard_regen": 2, "selected_hat": "treasure_hat", "deaths_bowspleef": 44, "bloodwizard_regen": 1, "coins": 1294, "bloodwizard_explode": 1, "kills_capture": 972, "witherwizard_explode": 2, "kineticwizard_regen": 0, "wins_bowspleef": 1, "packages": [ "wither_skull", "treasure_hat" ], "deaths_capture": 563, "tags_bowspleef": 858 } }, "uuid": "2d8cf844fa3441c38d4e597b32697909", "testPass": true, "playername": "destruc7i0n", "firstLogin": 1377178153134, "spec_always_flying": true, "achievements": { "paintball_wins": 43, "walls3_wins": 14, "quake_wins": 10, "tntgames_bow_spleef_wins": 1, "tntgames_wizards_wins": 79, "vampirez_survivor_wins": 0, "vampirez_kill_vampires": 9, "vampirez_coins": 209, "paintball_coins": 42375, "paintball_kills": 1038, "blitz_kills": 167, "arena_climb_the_ranks": 934, "general_coins": 249794, "walls_wins": 23, "walls3_kills": 141, "blitz_wins": 5, "arena_bossed": 4, "tntgames_tnt_run_wins": 0, "quake_killing_sprees": 20, "walls3_coins": 3842, "arena_gladiator": 3, "vampirez_kill_survivors": 14, "quake_kills": 2519, "walls_coins": 490, "blitz_coins": 6013, "arena_gotta_wear_em_all": 0, "general_wins": 171, "walls_kills": 25 }, "spec_night_vision": true, "thanksSent": 18, "displayname": "destruc7i0n", "achievementsOneTime": [ "general_first_join", "general_vip", "general_first_game", "general_first_chat", "general_first_friend", "quake_my_way", "general_use_portal", "general_join_vip_lobby", "general_youtuber", "tntgames_wizards_first_win", "vampirez_vampire_shop", "walls3_find_chest", "general_vip_plus", "general_use_pet", "blitz_first_game", "general_first_party", "blitz_first_blood", "quake_good_guy_gamer", "quake_bogof", "quake_doubling_up", "quake_first_kill", "quake_billy_talent", "quake_humiliation", "blitz_full_inventory", "blitz_seven_kits", "paintball_unlock_killstreaks", "walls3_first_skill_upgrade", "walls3_win_with_living_wither", "walls3_win_before_deathmatch", "walls3_mine_diamond", "walls3_kill_with_groopo", "general_friends_25", "walls3_attack_wither", "arena_offensive", "blitz_use_wolf_tamer", "blitz_spawn_horse", "paintball_no_killstreaks", "quake_looking_fancy", "paintball_last_kill", "paintball_activate_leeroy_jenkins", "vampirez_vampire_fang_kill", "vampirez_blood", "arena_totem_destroyer", "walls_revenge", "walls_craft_flint", "walls_first_kit", "walls_get_diamond_sword", "walls_no_team_deaths", "paintball_unlock_hat", "quake_what_have_i_done", "paintball_combo", "arcade_pig_fishing_super_bacon", "arcade_trampolinio_red_wool", "walls3_first_gathering_skill_upgrade", "general_buy_golem", "vampirez_purchase_sword", "blitz_kill_without_kit", "blitz_enchant_sword" ], "networkExp": 5109, "gadget": "MAGIC_9_BALL", "vanityTokens": 400, "networkLevel": 5, "notifications": false, "knownAliases": [ "destruc7i0n" ], "tipsSent": 3, "eulaCoins": true, "newClock": "LVL2", "packages": [ "vip", "pet_name", "pet_hat" ], "mostRecentMinecraftVersion": 47, "spec_auto_teleport": true, "fly": true, "settings": { "autoSpawnPet": true, "chatAlerts": true, "playerVisibility": false }, "spec_speed": 4, "karma": 13080, "lastLogin": 1418177737908, "quests": { "space_mission": { "completions": [ { "time": 1400605954009 }, { "time": 1417473159886 } ] }, "explosive_games": { "completions": [ { "time": 1414934448588 }, { "time": 1415478532729 } ] }, "tnt_addict": { "active": { "started": 1415052851873, "objectives": { "win": 1 } }, "completions": [ { "time": 1404829027957 }, { "time": 1414935082753 } ] }, "megawaller": { "active": { "started": 1415540314029, "objectives": { "kill": 3 } }, "completions": [ { "time": 1400611184445 }, { "time": 1412371273330 }, { "time": 1415138832442 }, { "time": 1415397132750 } ] }, "halloween2014": { "completions": [ { "time": 1414789606444 } ] }, "waller": { "active": { "started": 1405520101515, "objectives": {} }, "completions": [ { "time": 1405434596325 } ] }, "warriors_journey": { "active": { "started": 1407247955379, "objectives": { "tntwin": 3, "blitzkill": 5, "megawallswin": 1, "vampirezkillvamps": 1, "paintballwin": 2, "quake25kill": 26 } }, "completions": [ { "time": 1405434596326 } ] }, "paintball_expert": { "completions": [ { "time": 1401052261158 }, { "time": 1402961213473 }, { "time": 1405520523611 }, { "time": 1405695935526 }, { "time": 1414790938485 }, { "time": 1414932095539 }, { "time": 1415455705193 }, { "time": 1415550288384 } ] }, "blitzerk": { "active": { "started": 1415655376766, "objectives": { "killblitz10": 10 } }, "completions": [ { "time": 1405701811044 }, { "time": 1415539757530 } ] }, "gladiator": { "active": { "started": 1405433426532, "objectives": {} }, "completions": [ { "time": 1404830200258 } ] }, "serial_killer": { "active": { "started": 1405434615524, "objectives": { "megawalls": 28, "paintball": 55, "blitz": 35, "quake": 85, "tnt": 55 } } } }, "_id": "516bf6750cf2e73cea2a13a9" }, "success": true } }

我不确定这里有什么问题, 有人可以帮助它以json.dumps格式打印吗?感谢

1 个答案:

答案 0 :(得分:1)

您的JSON格式不正确,因为您在JSON字符串的末尾有一个额外的}。请使用http://jsonlint.com/

进行检查

该网站的错误消息是:

Parse error on line 587:
 ...  "success": true}}
 ---------------------^
Expecting 'EOF'