Home python ValueError: too many values ​​to unpack (expected 2) (enough variables to decompress...

ValueError: too many values ​​to unpack (expected 2) (enough variables to decompress values)

Author

Date

Category

This code:

import requests
Import Pandas AS PD
names = [ 'Abram /', 'Acker /', 'Acton /', 'Addington /', 'Adley /', 'Ainsley /', 'Ainsworth /', 'Alby /', 'Allerton /', 'Alston / ',' Altham / ',' Alton / ',' Anderton / ',' Ansley / ',' Anstey / ',' Appleton / ',' Asheton / ',' Ashley / ',' Ashton / ',' Astley / ',' Atherton / ',' Atterton / ',' Axton / ',' Badger / ']
c = 0
while c & lt; 24:
  response = requests.get ( 'https://www.instagram.com/', params = [names [c]])
  if response.status_code == 200:
    print ( 'Success!')
  elif response.status_code == 404:
    print ( 'Not Found.')
  ELSE:
    print ( 'Unknown Error')
  c = + 1

It is an error:

traceback (most recent call last):
File "/home/anon/eclipse-workspace/3/src/file3.py", line 11, in & lt; module & gt;
response = requests.get ( 'https://www.instagram.com/', params = [names [c]])
File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
  return request ( 'get', url, params = params, ** kwargs)
 File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
  return session.request (method = method, url = url, ** kwargs)
 File "/usr/lib/python3/dist-packages/requests/sessions.py", line 519, in request
  prep = self.prepare_request (req)
 File "/usr/lib/python3/dist-packages/requests/sessions.py", line 452, in prepare_request
  p.prepare (
 File "/usr/lib/python3/dist-packages/requests/models.py", line 313, in prepare
  self.prepare_url (url, params)
 File "/usr/lib/python3/dist-packages/requests/models.py", line 431, in prepare_url
  enc_params = self._encode_params (params)
 File "/usr/lib/python3/dist-packages/requests/models.py", line 97, in _encode_params
  for k, vs in to_key_val_list (data):
ValueError: too many values ​​to unpack (expected 2)

Prompt, how they can be corrected


Answer 1, Authority 100%

This error translates too lot variables to decompress values. We look at the string with a comment in my code and look at the same line in your – and see you there: params = [names [c]] then you take the value of one item, and turn it into a list of a single element (because everything is put in square parenthesis). Remove them, and the code is now working. As the request is now passed variable

import requests
Import Pandas AS PD
names = [ 'Abram /', 'Acker /', 'Acton /', 'Addington /', 'Adley /', 'Ainsley /', 'Ainsworth /', 'Alby /', 'Allerton /', 'Alston / ',' Altham / ',' Alton / ',' Anderton / ',' Ansley / ',' Anstey / ',' Appleton / ',' Asheton / ',' Ashley / ',' Ashton / ',' Astley / ',' Atherton / ',' Atterton / ',' Axton / ',' Badger / ']
c = 0
while c & lt; 24:
  response = requests.get ( 'https://www.instagram.com/', params = names [c]) # error here
  if response.status_code == 200:
    print ( 'Success!')
  elif response.status_code == 404:
    print ( 'Not Found.')
  ELSE:
    print ( 'Unknown Error')
  c = + 1
Previous articleRTOOLS
Next articlePython, Replace

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions