Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Required parameter volume_percent missing, even though it is sent

Solved!

Required parameter volume_percent missing, even though it is sent

Plan

Premium

Country

US

Device

PC

Operating System

Windows 10

 

My Question or Issue

I am making calls to the Spotify API using the Python Requests module, attempting to change the volume of the player programmatically. 

My code:

def setVolume(volume=-1):
    if 0 > volume or volume > 100:
        return -1
    data={'volume_percent': volume}

    print(data)
    req = requests.put('https://api.spotify.com/v1/me/player/volume', data=data, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + requestToken.access_token})
    print(req.request.body)
    
    if req.status_code == requests.codes.unauthorized:
        requestToken.access_token = requestToken()
        return setVolume(volume)
    print(req.text)
    return

When running the function, I get this printout:

{'volume_percent': 36} << data
volume_percent=36 << req.request.body
{ "error" : { "status" : 400, "message" : "Required parameter volume_percent missing" } } << req.text

 

 

Reply

Accepted Solutions
Marked as solution

You're sending the volume request in the HTTP body, not in the query string. Read the requests documentation.

View solution in original post

3 Replies

The volume percent should be present in the query string. Read the documentation.

Correct, and as shown by the output, it is provided to the request and is sent to the API, which is why I am confused about the server saying it didn't receive the data
Marked as solution

You're sending the volume request in the HTTP body, not in the query string. Read the requests documentation.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random