fastlane: "unexpected token at 'Bad Request'" from Spaceship when attempting to repair a provisioning profile

New Issue Checklist

Issue Description

I have a ruby script (see below) that I use to find, check status, repair / force repair, and download a provisioning profile. This has been working for at least two weeks until last night when I encountered errors in my build jobs (script is run as part of a Jenkins CI job).

I have manually called the ruby script (some values changed for obvious reasons) and see the below in terminal, and I’m wondering if anyone knows what is happening?

I have uninstalled and reinstalled fastlane, and see the same results.

Terminal command:

./download_check_and_repair_specific_provisioning_profile.rb "me@me.com" "password" "Team Name" "TeamID" "ProfileName" "/Users/me/Desktop/" "1" "1"

Command output:

  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    |
    | - START - Check, Repair and Download Provisioning Profile v1.0.2 - 19th August 2016 ----

       Logging into Developer Portal as: 'me@me.com'

       Selecting team: 'TeamID (Team Name)'

       Finding profile named: 'ProfileName'

       Forcing repair of profile named: 'ProfileName'

/Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/json-2.0.2/lib/json/common.rb:156:in `parse': 743: unexpected token at 'Bad Request' (Faraday::ParsingError)
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/json-2.0.2/lib/json/common.rb:156:in `parse'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response/parse_json.rb:11:in `block in <class:ParseJson>'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response_middleware.rb:48:in `call'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response_middleware.rb:48:in `parse'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response_middleware.rb:39:in `process_response'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response_middleware.rb:32:in `block in call'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday_middleware-0.10.0/lib/faraday_middleware/response_middleware.rb:30:in `call'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/client.rb:411:in `block in send_request'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/client.rb:328:in `with_retry'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/client.rb:410:in `send_request'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/client.rb:385:in `request'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/portal/portal_client.rb:374:in `repair_provisioning_profile!'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/portal/provisioning_profile.rb:349:in `block in update!'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/client.rb:328:in `with_retry'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/portal/provisioning_profile.rb:348:in `update!'
    from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spaceship-0.31.3/lib/spaceship/portal/provisioning_profile.rb:321:in `repair!'
    from ./download_check_and_repair_specific_provisioning_profile.rb:46:in `<main>'

Ruby script:

#!/usr/bin/env ruby
# This script will use Spaceship - part of the Fastlane tools - to login to the developer portal, optionally check the status of, and repair a profile, and download a profile.

the_script_version="1.0.2 - 19th August 2016"

puts ""
puts "     ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
puts "    |"
puts "    | - START - Check, Repair and Download Provisioning Profile v#{the_script_version} ----"
puts ""

the_user_name = ARGV[0]
the_user_password = ARGV[1]
the_team_name = ARGV[2]
the_team_id = ARGV[3]
the_profile_name = ARGV[4]
base_profile_path = ARGV[5]
allow_repair_of_profile = ARGV[6]
force_repair_of_profile = ARGV[7]

require "spaceship"
begin
    # Login
    puts "       Logging into Developer Portal as: '#{the_user_name}'"
    puts ""
    Spaceship.login(the_user_name, the_user_password)

    # Select team
    puts "       Selecting team: '#{the_team_id} (#{the_team_name})'"
    puts ""
    Spaceship.client.team_id = the_team_id

    # Find the exact profile we're looking for
    puts "       Finding profile named: '#{the_profile_name}'"
    puts ""
    my_profile = Spaceship.provisioning_profile.all.find { |p| p.name == the_profile_name }

    # Check if we are going to repair profiles at all
    # First check if we want to force the repair of the profile
    # Forcing will override wether we have deciced to repair profiles or not.
    if force_repair_of_profile == "1"
        # Forcing the repair of the profile
        puts "       Forcing repair of profile named: '#{the_profile_name}'"
        puts ""

        my_profile.repair!

        # Find the profile again. This is because the ID will likely have changed due to repairing and 'my_profile' is no longer valid
        my_profile = Spaceship.provisioning_profile.all.find { |p| p.name == the_profile_name }
    else
        # We are not forcing the repair of a profile. Check wether we do want to repair the profile at all
        if allow_repair_of_profile == "0"
            # We don't want to repair the profile
            puts "       Profile named '#{the_profile_name}' will not be repaired"
            puts ""
        else
            # We do want to repair the profile
            puts "       Attempting to repair profile named '#{the_profile_name}'"
            puts ""
            # Check the status of the profile
            my_profile_status = my_profile.status
            puts "       Status of profile: '#{the_profile_name}' is '#{my_profile_status}'"
            puts ""

            if my_profile_status == "Active"
                # Profile status is active. We do not need to repair it.
                puts "       Profile: '#{the_profile_name}' does not need to be repaired."
                puts ""
            else
                puts "       Profile: '#{the_profile_name}' needs to be repaired."
                puts "       Repairing profile named: '#{the_profile_name}'"
                puts ""

                # Find the profile again. This is because the ID will likely have changed due to repairing and 'my_profile' is no longer valid
                my_profile = Spaceship.provisioning_profile.all.find { |p| p.name == the_profile_name }
                my_profile.repair!

            end
        end
    end

    # Download the profile
    the_profile_name = the_profile_name.tr(' ', '_')
    the_profile_path = "#{base_profile_path}#{the_profile_name}.mobileprovision"
    puts "       Downloading profile named named: '#{the_profile_name}' to: '#{the_profile_path}'"
    puts ""
    File.write(the_profile_path, my_profile.download)
end


puts ""
puts "    | - END - Check, Repair and Download Provisioning Profile ----"
puts "    |"
puts "     ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"

I have also called Spaceship directly from terminal and issued these commands:

pry(main)> Spaceship.select_team
(Selected my team)

pry(main)> my_profile = Spaceship.provisioning_profile.all.find { |p| p.name == "ProfileName" }

(Profile data was returned)

pry(main)> my_profile.repair!

The result of the last command was:

Faraday::ParsingError: 743: unexpected token at 'Bad Request'
from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/json-2.0.2/lib/json/common.rb:156:in `parse'

Environment

fastlane version (run fastlane -v): fastlane 1.101.0

Do you use bundler to execute fastlane (i.e. bundle exec fastlane)? no

Do you use a Ruby environment manager (e.g. chruby, rbenv, rvm)? rbenv

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 42 (10 by maintainers)

Most upvoted comments

I have met the issue, and update to spaceship (0.31.6) solved my problem. Thank you.

gem sources --add https://rubygems.org --remove https://ruby.taobao.org/ āžœ work sudo gem update spaceship Password: Updating installed gems Updating spaceship Fetching: spaceship-0.31.6.gem (100%) Successfully installed spaceship-0.31.6 Parsing documentation for spaceship-0.31.6 Installing ri documentation for spaceship-0.31.6 Installing darkfish documentation for spaceship-0.31.6 Gems updated: spaceship

@TKBurner problem solved! the 0.32.0 version is fine . i just use it in a wrong way. V_V

Great, I’m going to close this issue as it was specific to repair_provisioning_profile.

If, after updating to 0.31.7, you are still getting a Bad Request error, please follow https://github.com/fastlane/fastlane/issues/5827 where we will continue to look for a fix. šŸ‘

@asfalcone that seems to be fixed ! thanks a lot !!!