Home > Mobile >  for header in headers.items(): AttributeError: 'set' object has no attribute 'items&#
for header in headers.items(): AttributeError: 'set' object has no attribute 'items&#

Time:04-26

I am trying to make a coin up script for Likeplus app which works with its api. However when I run this script, it gives an AttributeError:

for header in headers.items():
AttributeError: 'set' object has no attribute 'items'

This is my code:

import requests
headers = {
       
    'X-Market: zarinpal'
    'X-Lan: en'
    'X-Version: 4'
    'X-Access: cafegram'
    'Content-Type: application/json; charset=utf-8'
    'User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; 706SH Build/S2004)'
    'Host: followerpshop.xyz'
    'Connection: Keep-Alive'
    'Accept-Encoding: gzip'
    'Content-Length: 832'

}

data = input('Enter your order data: ')
data = f'{data}'
while True:
  re = requests.post("https://followerpshop.xyz/FollowPlus/v2/otpStatus.php", headers=headers, data=data).text
  print(re)

headers = {
       
    'X-Market: zarinpal'
    'X-Lan: en'
    'X-Version: 4'
    'X-Access: cafegram'
    'Content-Type: application/json; charset=utf-8'
    'User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; 706SH Build/S2004)'
    'Host: followerpshop.xyz'
    'Connection: Keep-Alive'
    'Accept-Encoding: gzip'
    'Content-Length: 832'

}

data = ("Enter your data: ")
data = f'{data}'

re = requests.post("https://followerpshop.xyz/FollowPlus/v2/otpStatus.php", headers=headers, data=data).text
  
print(re)

What is wrong with this code, and how can I fix it?

CodePudding user response:

headers is a set of strings, rather than a dictionary.

You need to place the colon outside of the quotes, like so:

headers = {
    'X-Market': 'zarinpal',
    'X-Lan': 'en',
    'X-Version': '4',
    'X-Access': 'cafegram',
    'Content-Type': 'application/json; charset=utf-8',
    'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 10; 706SH Build/S2004)',
    'Host': 'followerpshop.xyz',
    'Connection': 'Keep-Alive',
    'Accept-Encoding': 'gzip',
    'Content-Length': '832'
}

CodePudding user response:

headers is of set data type not a dictionary. If your declaration of headers is correct, you can simply iterate over it like:

for header in headers:
    ***Your code***
  • Related