Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 AttributeError: 'set' object has no attribute 'items
Hi All,

I am having problems trying to work out what I have done wrong, any help would be much appreciated :)

The error points to:

for header in headers.items():

AttributeError: 'set' object has no attribute 'items'

import requests
import pandas as pd
from lxml import etree

def getXML(toDate, fromDate, dayType):
    url =""
    headers = {'Content-Type: application/soap+xml; charset=utf-8'}
    body ="""
    <soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12="">
            <GetPublicationDataWMResponse xmlns="">
                        <string>LNG Stock Level</string>
      """% (toDate, fromDate, dayType)

    response =, data=body, headers=headers)

    return response.content

df = pd.DataFrame(columns=("applicable_at","applicable_for","name","value","generated","quality_indicator","substituted","created_date"))

for pd_date in pd.date_range('2016-03-14', '2016-03-15'):
    day = pd_date.strftime('%Y-%m-%d')
    root = etree.fromstring(getXML(day,day,"gasday"))
    #map prefix 'd' to the default namespace URI
    ns = {'d': ''}
    publication_objects = root.xpath('//d:CLSMIPIPublicationObjectBE', namespaces=ns)
    for obj in publication_objects:
        name = obj.find('d:PublicationObjectName', ns).text
        data = obj.find('d:PublicationObjectData/d:CLSMIPIPublicationObjectBE', ns)
        applicable_at = pd.to_datetime(data.find('d:ApplicableFor', ns).text, format ='%Y-%m-%dT%H:%M:%SZ')
        applicable_for = pd.to_datetime(data.find('d:ApplicableFor', ns).text, format ='%Y-%m-%dT%H:%M:%SZ')
        value = float(data.find('d:Value', ns).text)
        generated = pd.to_datatime(data.find('d:GeneratedTimeStamp', ns).text, format ='%Y-%m-%dT%H:%M:%SZ')
        quality_indicator = data.find('d:Value', ns).text
        substituted = data.find('d:Substituted', ns).text
        created_date = pd.to_datetime(data.find('d:CreatedDate', ns).text, format ='%Y-%m-%dT%H:%M:%SZ')
        df.loc[len(df) +1] = [applicable_at, applicable_for,name, value, generated, quality_indicator, substituted, created_date]

The line 7:
(Apr-29-2018, 03:31 PM)hey_arnold Wrote: headers = {'Content-Type: application/soap+xml; charset=utf-8'}

Is a set, not a dictionary as it shall be. I tried with:
headers = {'Content-Type': 'application/soap+xml', 'charset': 'utf-8'}
and does not produce an error, but I do not know if it what you want...
Hello, the headers argument should be a dictionary, but you assigned the headers variable to a set with a single string argument in line 7.

Check this tutorial, in particular "Working with headers" section.
Thanks :)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  AttributeError: (“module 'pandas' has no attribute 'rolling_std'” Mariana136 4 1,801 Sep-23-2019, 12:56 PM
Last Post: Mariana136
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 12,366 May-29-2019, 02:48 AM
Last Post: heiner55
  Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv' NSearch 9 5,212 Apr-22-2019, 05:05 PM
Last Post: Yoriz
  AttributeError: 'NoneType' object has no attribute 'all' synthex 2 1,416 Mar-07-2019, 11:11 AM
Last Post: synthex
  Please help with AttributeError: 'Netz' object has no attribute 'conv' DerBerliner 2 954 Feb-27-2019, 06:01 PM
Last Post: DerBerliner
  'list' object has no attribute 'reshape' SamSoftwareLtd 1 6,343 Nov-04-2018, 10:38 PM
Last Post: stullis
  AttributeError: Can't get attribute 'Individual' on <module 'deap.creator' DomClout 4 3,021 Jul-27-2018, 09:05 PM
Last Post: Vysero
  AttributeError: module 'mnist' has no attribute 'train_images' pythonbeginner 1 3,044 Jun-14-2018, 09:29 PM
Last Post: snippsat
  AttributeError: module 'plotly' has no attribute 'offline' charlesczc 8 8,637 Jan-21-2018, 08:34 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)